IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JDeveloper Java Discussion :

Bouton Parcourir en java


Sujet :

JDeveloper Java

  1. #1
    Membre confirmé
    Inscrit en
    Mai 2008
    Messages
    112
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 112
    Par défaut Bouton Parcourir en java
    Je suis débutante en java et j'utilise Jdeveloper 10.1.3.0 et je veux creer un bouton "parcourir" comme celui de windows.g trouvé d exemple dans dotres forum mais ça na pa marché dans mon prog.paske g pas su exactement ou l'inserer.voici mon code source:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    public class FormScan extends JFrame {
        private JTextField jTextFieldchemin = new JTextField();
        private JLabel jLabelchemin = new JLabel();
        private JButton scanner = new JButton();
        private JLabel jLabelresultat = new JLabel();
     
        public FormScan() {
           addWindowListener(new WindowAdapter() 
          {public void windowClosing(WindowEvent e)          {intaction=_popupTransactionDialog();
    if (action!=JOptionPane.CLOSED_OPTION){ panelBinding.releaseDataControl(); statusBar.release();System.exit(0);} } }); 
        }
     
        private GridLayout gridLayout = new GridLayout();
        private BorderLayout borderLayout = new BorderLayout();
        private JUPanelBinding panelBinding = new JUPanelBinding("FormScanPageDef");
        private JUStatusBar statusBar = new JUStatusBar();
        private JPanel topPanel = new JPanel();
        private JPanel dataPanel = new JPanel();
        private JUNavigationBar hiddenNavBar = new JUNavigationBar();
     
     
     
     
        private void registerProjectGlobalVariables(BindingContext bindCtx) {
            JUUtil.registerNavigationBarInterface(panelBinding, bindCtx);
        }
     
        private void unRegisterProjectGlobalVariables(BindingContext bindCtx) {
            JUUtil.unRegisterNavigationBarInterface(panelBinding, bindCtx);
        }
     
        /**the JbInit method
         */
        public void jbInit() throws Exception {
            dataPanel.setLayout(null);
            this.getContentPane().setLayout(gridLayout);
            topPanel.setLayout(borderLayout);
            this.getContentPane().add(topPanel);
            this.setSize(new Dimension(696, 461));
            this.setTitle("Scan");
            dataPanel.add(jLabelresultat, null);
            dataPanel.add(scanner, null);
            dataPanel.add(jLabelchemin, null);
            dataPanel.add(jTextFieldchemin, null);
            topPanel.add(dataPanel, BorderLayout.CENTER);
            topPanel.add(statusBar, BorderLayout.SOUTH);
            hiddenNavBar.setModel(JUNavigationBar.createPanelBinding(panelBinding, hiddenNavBar));
     
            scanner.setText("Scanner");
            scanner.setBounds(new Rectangle(580, 25, 100, 25));
     
            scanner.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            scanner_actionPerformed(e);
                        }
                    });
            jTextFieldchemin.setBounds(new Rectangle(165, 25, 355, 25));
            jLabelchemin.setText("Chemin Module");
            jLabelchemin.setBounds(new Rectangle(55, 30, 95, 15));
     
            statusBar.setModel(JUStatusBar.createPanelBinding(panelBinding, statusBar));
        }
     
        public static void main(String [] args) {
            try {
                UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
            } catch (ClassNotFoundException cnfe) {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception exemp) {
                    exemp.printStackTrace();
                }
            } catch (Exception exemp) {
                exemp.printStackTrace();
            }
            try {
                JUMetaObjectManager.setErrorHandler(new JUErrorHandlerDlg());
                JUMetaObjectManager mgr = JUMetaObjectManager.getJUMom();
                mgr.setJClientDefFactory(null);
                BindingContext ctx = new BindingContext();
                ctx.put(DataControlFactory.APP_PARAM_ENV_INFO, new JUEnvInfoProvider());
                ctx.setLocaleContext(new DefLocaleContext(null));
                HashMap map = new HashMap(4);
                map.put(DataControlFactory.APP_PARAMS_BINDING_CONTEXT, ctx);
                mgr.loadCpx("data.DataBindings.cpx" , map);
                final FormScan frame = new FormScan();
                frame.setBindingContext(ctx);
                frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                Dimension frameSize = frame.getSize();
                if (frameSize.height > screenSize.height) {
                    frameSize.height = screenSize.height;
                }
                if (frameSize.width > screenSize.width) {
                    frameSize.width = screenSize.width;
                }
                frame.setLocation((screenSize.width - frameSize.width)/2, (screenSize.height - frameSize.height)/2);
                frame.setVisible(true);
            } catch (Exception ex) {
                JUMetaObjectManager.reportException(null, ex, true);
                System.exit(1);
            }
        }
    }
    Merci

  2. #2
    Membre confirmé
    Inscrit en
    Mai 2008
    Messages
    112
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 112
    Par défaut
    Salut,
    Désolé je c que mon code n'est pas trés bien soigné.Mais c parske il ya du code qui se rajoute automatiquement en Jdev ,alors je laisse l'essentiel mnt.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    public class FormScan extends JFrame {
    private JTextField jTextFieldchemin = new JTextField();
    private JLabel jLabelchemin = new JLabel();
    private JButton scanner = new JButton();
    private JLabel jLabelresultat = new JLabel();
    public FormScan() {
    ...
     
    /**the JbInit method
    public void jbInit() throws Exception {
    ...//des controles rajouté par jdev
    scanner.setText("Scanner");
    scanner.setBounds(new Rectangle(580, 25, 100, 25));
    scanner.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    scanner_actionPerformed(e);
    }
    });
    jTextFieldchemin.setBounds(new Rectangle(165, 25, 355, 25));
    jLabelchemin.setText("Chemin Module");
    jLabelchemin.setBounds(new Rectangle(55, 30, 95, 15));
    public static void main(String [] args) {..//des controles rajouté par jdev}
    }

    Ma quetion est la suivante:je veux placer un bouton "Parcourir"(que je n'est pas encore créé) comme celui de windows afin de pouvoir choisir un fichier et le mettre dans le textfield "jTextFieldchemin".

    Si vous avez une suggestion svp aidez moi

  3. #3
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 483
    Par défaut
    Pour parcourir les fichier, regarde le composant JFileChooser de l'api swing.

  4. #4
    Membre confirmé
    Inscrit en
    Mai 2008
    Messages
    112
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 112
    Par défaut
    g essayé avec ce composant,mais g pa su ou le mettre dans mon code.est ce que je crée un bouton puis je le transforme en JtextChooser?keskil fo rajouter apres la création?Je suis trés confuse(surtout ke je suis débutante en java).
    Voici mon code,si vous pouvez m'aider

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    public class FormScan extends JFrame {
    private JTextField jTextFieldchemin = new JTextField();
    private JLabel jLabelchemin = new JLabel();
    private JButton scanner = new JButton();
    private JLabel jLabelresultat = new JLabel();
    public FormScan() {
    ...
     
    /**the JbInit method
    public void jbInit() throws Exception {
    ...//des controles rajouté par jdev
    scanner.setText("Scanner");
    scanner.setBounds(new Rectangle(580, 25, 100, 25));
    scanner.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    scanner_actionPerformed(e);
    }
    });
    jTextFieldchemin.setBounds(new Rectangle(165, 25, 355, 25));
    jLabelchemin.setText("Chemin Module");
    jLabelchemin.setBounds(new Rectangle(55, 30, 95, 15));
    public static void main(String [] args) {..//des controles rajouté par jdev}
    }

  5. #5
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 483
    Par défaut
    Tu crée un JButton, tu lui donne un nom, et dans son actionlistener, tu fait appel au composant JFileChoooser (c'est la boite de dialogue de choix de fichier). Quand c'est fait, tu récupère le nom du fichier choisi (voir l'api de JFileChooser) et tu en fait ce que tu veux.

    Exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    JButton button = new JButton("parcourir");
    button.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            JFileChooser chooser = new JFileChooser();
            int returnVal = chooser.showOpenDialog(parent);
            if(returnVal == JFileChooser.APPROVE_OPTION) {
               System.out.println("You chose to open this file: " +
                    chooser.getSelectedFile().getName());
        }
     
        }
    } );

  6. #6
    Membre confirmé
    Inscrit en
    Mai 2008
    Messages
    112
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 112
    Par défaut
    Meeeeeeeerci énormément pour t conseils.ça a marché finalement.

Discussions similaires

  1. [C#] Créer un bouton parcourir
    Par trotters213 dans le forum Windows Forms
    Réponses: 9
    Dernier message: 24/01/2012, 18h22
  2. bouton parcourir sous java
    Par z_meryem dans le forum Interfaces Graphiques en Java
    Réponses: 1
    Dernier message: 20/04/2008, 01h52
  3. Bouton Parcourir en Java
    Par sticks dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 03/05/2007, 13h47
  4. Mettre une image a la place du bouton parcourir
    Par Death83 dans le forum Langage
    Réponses: 3
    Dernier message: 04/09/2005, 20h16
  5. Réponses: 4
    Dernier message: 20/04/2005, 12h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo