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

Agents de placement/Fenêtres Java Discussion :

ensembles des JPanel


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Membre averti
    Inscrit en
    Février 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 35
    Par défaut ensembles des JPanel
    salut, au secours
    je suis en ce moment entrain de realiser la partie graphique de mon projet.
    j'ai un menu et lorsque je clique sur un item du menu, je voudrais faire apparaitre suivant l'item, le jpanel correspondant dans mon jframe principal mais dans une position et taille bien determiner que je viens de les preciser.
    ça suppose donc que j'ai plusieurs classes dérivant de jpanel.
    Mon pb est comment le faire.
    j'ai penser à faire des events.
    et pour chaque event , créer une classe de type Jpanel et l'intégrer au jframe .

    si quelqu'un voit une solution plus simple!
    j'attends vos conseils
    merci d'av

  2. #2
    Rédacteur
    Avatar de darrylsite
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    1 299
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2007
    Messages : 1 299
    Par défaut
    Tu peux par exemple placer un layout dans le frame. Et utiliser la methode add et remove pour ajouter ou retirer les jpanel. D'autre part, je ne vois d'autre solution que de créer une classe derivant de Jpanel et l'intégrer au layout.

  3. #3
    Membre averti
    Inscrit en
    Février 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 35
    Par défaut
    pouvez vous m'expliquer par un exemple de code svp

  4. #4
    Membre averti
    Inscrit en
    Février 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 35
    Par défaut
    ah je viens de vous expliquer plus alors:
    je vais faire un menu et lorsque je clique sur un item un jpanel s'affiche. a chaque item il correspond un jpanel et les panels s'affichent tous dans la meme position mais chaque panel ne s'affiche pas que lorsque je clique sur l'item correspondant pouvez vous me donnez une solution svp

  5. #5
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2004
    Messages
    68
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2004
    Messages : 68
    Par défaut
    quand vous creez votre nouveau JPanel, apres l'avoir ajouté, essayez de faire

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    votreConteneur.validate();

  6. #6
    Membre averti
    Inscrit en
    Février 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 35
    Par défaut
    Bonjour j'ai essayer avec ce code mais rien ne s'affiche:
    pour ma classe JFrame:
    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
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
     
    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.Dimension;
    import javax.swing.*;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * ff.java
     *
     * Created on 18 févr. 2009, 22:01:20
     */
     
    /**
     *
     * @author Administrateur
     */
    public class ff extends javax.swing.JFrame {
     
        /** Creates new form ff */
        public ff() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jPanel1 = new javax.swing.JPanel();
            jPanel2 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 309, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
     
            jButton1.setText("panel1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            jButton2.setText("panel2");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButton1)
                        .addComponent(jButton2))
                    .addGap(18, 18, 18)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(48, 48, 48)
                    .addComponent(jButton1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jButton2)
                    .addContainerGap(195, Short.MAX_VALUE))
            );
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
     
            pack();
        }// </editor-fold>
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
     
           // TODO add your handling code here:
        Panel1 p1=new Panel1();
            if(evt.getSource()==jButton1)
            {p1.validate();
     
            }
        }
     
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
             Panel2 p2=new Panel2();
     
     
            if(evt.getSource()==jButton2)
            {p2.validate();
     
            }
        }
     
     
     
     
     
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
     
     
                    new ff().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        // End of variables declaration
     
    }
     
    pour ma classe panel1:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * Panel1.java
     *
     * Created on 18 févr. 2009, 21:57:48
     */
     
    /**
     *
     * @author Administrateur
     */
    public class Panel1 extends javax.swing.JPanel {
     
        /** Creates new form Panel1 */
        public Panel1() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            jLabel1 = new javax.swing.JLabel();
     
            jLabel1.setText("panel1");
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(26, 26, 26)
                    .addComponent(jLabel1)
                    .addContainerGap(342, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1)
                    .addContainerGap(275, Short.MAX_VALUE))
            );
        }// </editor-fold>                        
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JLabel jLabel1;
        // End of variables declaration                   
     
    }
    pour ma classe panel2:
    public class Panel2 extends javax.swing.JPanel {
     
        /** Creates new form Panel2 */
        public Panel2() {
            initComponents();
        }
     
     
        private void initComponents() {
     
            jLabel1 = new javax.swing.JLabel();
     
            jLabel1.setText("panel2");
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(33, 33, 33)
                    .addComponent(jLabel1)
                    .addContainerGap(335, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(27, 27, 27)
                    .addComponent(jLabel1)
                    .addContainerGap(259, Short.MAX_VALUE))
            );
        }                       
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JLabel jLabel1;
        // End of variables declaration                   
     
    }
    j'ai essayer avec ce petit exemple avant de l'appliquer sur mon interface svp quelqu'un m'aide

  7. #7
    Rédacteur
    Avatar de darrylsite
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    1 299
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2007
    Messages : 1 299
    Par défaut
    Tu ne dois pas faire de validate() sur le Panel, mais plutot sur ce qui contient le panel. Je t'ai conseiller de placer un Layout sur la Frame. Et c'est sur ce layout que tu vas ajouter les Panel et ensuite faire layout.validate().

  8. #8
    Membre averti
    Inscrit en
    Février 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 35
    Par défaut
    Merci pour votre reponse sayé c'est resolue je trouve une autre methode avec le cardlayout et si quelq'un a le meme pb besoin d'aide il peut utiliser le code suivant et n'hesiter pas a poser des questions
    c'est la classe principale
    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
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    import javax.swing.*;
    import java.awt.*;
     
        import java.awt.event.*;
    public class DE  extends JFrame implements ActionListener  {
    JPanel panneau1, panneau2;
      private CardLayout pile = new CardLayout();
        private JButton panel1;
        private JButton panel2;
    Panel2 p2;
     
     
      public DE(String titre){
        setTitle(titre);
                  setSize(300, 400);
                  Container c = getContentPane();
     
                  panneau1 = new JPanel();
     
                       c.add(panneau1);
                         panneau2 = new JPanel();
                  c.add(  panneau2, "North");
     
                  panneau1.setLayout(pile);
                Panel1 p1=new Panel1();
     
                  panneau1.add(p1,"1");
                p2 =new Panel2();
                    panneau1.add(p2,"2");
                  panel1 = new JButton("panel1");
                  panneau2.add(panel1);
                  panel1.addActionListener(this);
     
               panel2 = new JButton("panel2");
                 panneau2.add(panel2);
                panel2.addActionListener(this);
     
     
     
    }
    public void actionPerformed(ActionEvent a)
             {
     
     
                 if(   a.getSource() == panel1) pile.show(panneau1,"1"); 
              if(   a.getSource() == panel2)
                  pile.show(panneau1,"2");
     
     
     
             }
     
     
               public static void main (String [] args)
                {
                    JFrame f = new DE("Mise en forme");
                    f.setVisible(true);
               }
     
    }
     
    les classes des jpanel1 et jpanel2:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * Panel1.java
     *
     * Created on 18 févr. 2009, 21:57:48
     */
     
    /**
     *
     * @author Administrateur
     */
    public class Panel1 extends javax.swing.JPanel {
     
        /** Creates new form Panel1 */
        public Panel1() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jLabel1 = new javax.swing.JLabel();
     
            jLabel1.setText("panel1");
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(26, 26, 26)
                    .addComponent(jLabel1)
                    .addContainerGap(342, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1)
                    .addContainerGap(275, Short.MAX_VALUE))
            );
        }// </editor-fold>
     
     
        // Variables declaration - do not modify
        private javax.swing.JLabel jLabel1;
        // End of variables declaration
     
    }
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * Panel2.java
     *
     * Created on 18 févr. 2009, 21:58:31
     */
     
    /**
     *
     * @author Administrateur
     */
    public class Panel2 extends javax.swing.JPanel {
     
     
     
        /** Creates new form Panel2 */
        public Panel2() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            pan2 = new javax.swing.JLabel();
     
            pan2.setText("panel2");
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(33, 33, 33)
                    .addComponent(pan2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(322, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(27, 27, 27)
                    .addComponent(pan2)
                    .addContainerGap(259, Short.MAX_VALUE))
            );
        }
     
     
        // Variables declaration - do not modify
        private javax.swing.JLabel pan2;
        // End of variables declaration
     
    }

Discussions similaires

  1. Script permettant de créer l'ensemble des indexes d'une base
    Par matacars dans le forum MS SQL Server
    Réponses: 7
    Dernier message: 01/07/2005, 16h14
  2. [JPanel] superposer des JPanel
    Par Galima dans le forum Agents de placement/Fenêtres
    Réponses: 4
    Dernier message: 10/06/2004, 18h25
  3. Sauvegarder l'ensemble des DTS d'un serveur SQL
    Par maveric dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 05/02/2004, 19h20
  4. [JTree] Ouvrir/Fermer l'ensemble des noeuds
    Par Math_Caen dans le forum Composants
    Réponses: 3
    Dernier message: 07/04/2003, 14h01

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