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

AWT/Swing Java Discussion :

Structure de mon interface


Sujet :

AWT/Swing Java

  1. #1
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut Structure de mon interface
    Bonjour, voila je vous explique j'ai une interface graphique à concevoir et le fonctionnement est similaire à un site web: J'ai un panel en haut où il y a toutes les options et suivant les options le panel en dessous change. Comment faire? J'ai un panel pour ma page d'accueil, les autres je les supperpose sur celui ci? Ou je fais en sorte de les mettre sur le contentepane de la frame?
    J'ai essaye de creer d'autres panels et de les mettre sur le panel d'accueil mais quand j'execute l'appli les panels que j'ai rajouté est transparent alors que ses propriétés lui spécifient que non.

    Merci d'avance

  2. #2
    Membre expérimenté
    Inscrit en
    Janvier 2006
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 257
    Par défaut
    ba il faut que tu es un container dans lequel tu met le panel qui va bien au moment qui va bien

    et tu remove celui que te convient avant d'en ajouter un autre ...

  3. #3
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Oue ça ok mais pour la conception je supperpose tous mes panels sur le panel d'accueil et apres pour les actions je change les visibilités de chacun?

  4. #4
    Membre expérimenté
    Inscrit en
    Janvier 2006
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 257
    Par défaut
    ba non t'ajoute le bon dans le cotainer au moment ou il faut ...

  5. #5
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Ok je fais donc un fichier pour chaque panel supplementaire?

  6. #6
    Membre éprouvé
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut
    Bonjour,

    Est ce que tu peux essayer ceci et me dire si c'est ce que tu voulais ou ressemblant ?

    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
     
    public class Main extends JApplet implements ActionListener
    {
     
       private JPanel containerPane ;
       public void init()
       {
          JPanel globalPanel = new JPanel();
          globalPanel.setLayout(new BorderLayout());
     
          //3 radios boutons
          ButtonGroup buttonGroup1=new ButtonGroup();
          JRadioButton jRadioButton1=new JRadioButton("Panneau 1");
          JRadioButton jRadioButton2=new JRadioButton("Panneau 2");
          JRadioButton jRadioButton3=new JRadioButton("Panneau 3");
     
          JPanel panelNord = new JPanel();
          panelNord.setLayout(new FlowLayout(FlowLayout.LEFT,5,5));
     
          //Dans un groupe
          buttonGroup1.add(jRadioButton1);
          buttonGroup1.add(jRadioButton2);
          buttonGroup1.add(jRadioButton3);
     
          //pour lancer actionPerformed apres clic dessus
          jRadioButton1.addActionListener(this);
          jRadioButton2.addActionListener(this);
          jRadioButton3.addActionListener(this);
     
          panelNord.add(jRadioButton1);
          panelNord.add(jRadioButton2);
          panelNord.add(jRadioButton3);
     
          containerPane = new JPanel();
          containerPane.setLayout(new BorderLayout());
     
          globalPanel.add(panelNord,BorderLayout.NORTH);
          globalPanel.add(containerPane,BorderLayout.CENTER);
          //Le tout dans un scollpane
          this.getContentPane().add(new JScrollPane(globalPanel));
       }
     
       public void actionPerformed(ActionEvent e)
       {
          //detection du bouton cliqué et envoi commande change panneau
          JRadioButton btn = (JRadioButton)e.getSource();
          if("Panneau 1".equals(btn.getText()))
          {
             changePanel(1);
          }
          else if("Panneau 2".equals(btn.getText()))
          {
             changePanel(2);
          }
          else if("Panneau 3".equals(btn.getText()))
          {
             changePanel(3);
          }
       }
     
       //Change de panneau
       public void changePanel(int index)
       {
          //Suppression du contenu
          containerPane.removeAll();
          //creation d'un nouveau contenu
          Component cp = null;
          switch(index)
          {
             case 1:
                cp=new JList(new Object[]{"item 1","item 2","item 3"});
                break;
             case 2:
                cp=new JComboBox(new Object[]{"item 1","item 2","item 3"});
                break;
             case 3:
                cp=new JLabel("Label item 1 item 2 item 3");
                break;
          }
          //Ajout et mise a jour
          containerPane.add(cp,BorderLayout.NORTH);
          containerPane.revalidate();
          containerPane.repaint();
       }
    }
    Grosso modo ca fait un panneau avec 3 radio boutons en haut
    tu clic sur 1 : sa affiche une JList
    tu clic sur 2 : sa affiche une combobox
    tu clic sur 3 : sa affiche un JLabel

    A++

  7. #7
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Non c'est pas ça moi ma frame est decoupe en deux panels (haut et bas). En haut il y a tous mes conbobox et quand je change les valeurs de mes combos le panel du bas change. Exactement comme un site en php avec des includes: il y a un menu et quand on clique sur les liens la change mais le menu est toujours là.

  8. #8
    Membre expérimenté
    Inscrit en
    Janvier 2006
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 257
    Par défaut
    ba sa revient au meme ce que te propose NicoW... il faut que tu fasse un panel global decoupé en deux et en fonction de la selection de tes combobox tu affiche le bon panel dans le panel du bas ... Ou alors j'ai ptete rien compris ...

  9. #9
    Membre éprouvé
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut
    Deuxième chance pour moi !!

    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
     
     
    public class Main extends JApplet implements ActionListener
    {
     
       private JPanel containerPane ;
       private JLabel lblCbx1;
       private JLabel lblCbx2;
       private JLabel lblCbx3;
     
       public void init()
       {
          JPanel globalPanel = new JPanel();
          globalPanel.setLayout(new BorderLayout());
     
          //3 COMBOS
          JComboBox jComboBox1=new JComboBox(new Object[]{"cb1 A"  ,"cb1 B"  ,"cb1 C"});
          JComboBox jComboBox2=new JComboBox(new Object[]{"cb2 AA" ,"cb2 BB" ,"cb2 CC"});
          JComboBox jComboBox3=new JComboBox(new Object[]{"cb3 AAA","cb3 BBB","cb3 CCC"});
     
          JPanel panelNord = new JPanel();
          panelNord.setLayout(new FlowLayout(FlowLayout.LEFT,5,5));
     
          //pour lancer actionPerformed apres clic dessus
          jComboBox1.addActionListener(this);
          jComboBox2.addActionListener(this);
          jComboBox3.addActionListener(this);
          //retrouver d'ou vient l'action
          jComboBox1.setActionCommand("1");
          jComboBox2.setActionCommand("2");
          jComboBox3.setActionCommand("3");
     
          panelNord.add(jComboBox1);
          panelNord.add(jComboBox2);
          panelNord.add(jComboBox3);
     
          containerPane = new JPanel();
          containerPane.setBorder(BorderFactory.createTitledBorder("Pannneau changeant"));
          containerPane.setLayout(new GridLayout(3,1));
     
          lblCbx1 = new JLabel("rien de neuf pour cb1");
          lblCbx2 = new JLabel("rien de neuf pour cb2");
          lblCbx3 = new JLabel("rien de neuf pour cb3");
     
          containerPane.add(lblCbx1);
          containerPane.add(lblCbx2);
          containerPane.add(lblCbx3);
     
          globalPanel.add(panelNord,BorderLayout.NORTH);
          globalPanel.add(containerPane,BorderLayout.CENTER);
          //Le tout dans un scollpane
          this.getContentPane().add(new JScrollPane(globalPanel));
       }
     
       public void actionPerformed(ActionEvent e)
       {
          //detection du bouton cliqué et envoi commande change panneau
          JComboBox cb = (JComboBox)e.getSource();
          String chaine = cb.getSelectedItem().toString();
     
          switch(Integer.parseInt(e.getActionCommand()))
          {
             case 1:
                lblCbx1.setText(chaine);
                break;
             case 2:
                lblCbx2.setText(chaine);
                break;
             case 3:
                lblCbx3.setText(chaine);
                break;
          }
       }
    }
    Cette fois ci tu fais une modif sur un des trois combo du haut et cela change un JLabel qui va bien ....

    A++

  10. #10
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Voila sauf que moi je veux changer des panels et pas des labels. Je dois concevoir une grosse appli, je suis en stage et j'ai jamais fais de java de ma vie donc dsl si je fais boulet.


    Edit: en fait ton premier code est bon j'avais une erreur a la con que j'avais pas vu.

  11. #11
    Membre Expert
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Par défaut
    Citation Envoyé par swiixz
    Voila sauf que moi je veux changer des panels et pas des labels. Je dois concevoir une grosse appli, je suis en stage et j'ai jamais fais de java de ma vie donc dsl si je fais boulet.


    Edit: en fait ton premier code est bon j'avais une erreur a la con que j'avais pas vu.
    Ben te reste juste à adapter un tout petit peu ... Un peu d'effort, le but d'un stage c'est quand même d'apprendre

  12. #12
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Oui tout à fait merci bcp pour vos rep je vais essayer de comprendre correctement le code. Etant donné que l'appli est quand meme assez lourde (par là j'entend qu'il y a beaucoup d'elements) est ce que ca fonctionnerai si je faisais plusieurs fichiers car le switch va etre immense sinon. non?

  13. #13
    Membre éprouvé
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut
    Dernière chance mais ca ne doit pas être bien loin e ce que tu cherche ...

    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
     
    public class Main extends JApplet implements ActionListener
    {
     
       private JPanel containerPane ;
       private JPanel panelCbx1;
       private JPanel panelCbx2;
       private JPanel panelCbx3;
     
       public void init()
       {
          JPanel globalPanel = new JPanel();
          globalPanel.setLayout(new BorderLayout());
     
          //3 COMBOS
          JComboBox jComboBox1=new JComboBox(new Object[]{"cb1 A"  ,"cb1 B"  ,"cb1 C"});
          JComboBox jComboBox2=new JComboBox(new Object[]{"cb2 AA" ,"cb2 BB" ,"cb2 CC"});
          JComboBox jComboBox3=new JComboBox(new Object[]{"cb3 AAA","cb3 BBB","cb3 CCC"});
     
          JPanel panelNord = new JPanel();
          panelNord.setLayout(new FlowLayout(FlowLayout.LEFT,5,5));
     
          //pour lancer actionPerformed apres clic dessus
          jComboBox1.addActionListener(this);
          jComboBox2.addActionListener(this);
          jComboBox3.addActionListener(this);
          //retrouver d'ou vient l'action
          jComboBox1.setActionCommand("1");
          jComboBox2.setActionCommand("2");
          jComboBox3.setActionCommand("3");
     
          panelNord.add(jComboBox1);
          panelNord.add(jComboBox2);
          panelNord.add(jComboBox3);
     
          containerPane = new JPanel();
          containerPane.setBorder(BorderFactory.createTitledBorder("Pannneau changeant"));
          containerPane.setLayout(new GridLayout(3,1));
     
          panelCbx1 = new JPanel1("rien de neuf pour cb1");
          panelCbx2 = new JPanel2("rien de neuf pour cb2");
          panelCbx3 = new JPanel3("rien de neuf pour cb3");
     
          containerPane.add(panelCbx1);
          containerPane.add(panelCbx2);
          containerPane.add(panelCbx3);
     
          globalPanel.add(panelNord,BorderLayout.NORTH);
          globalPanel.add(containerPane,BorderLayout.CENTER);
          //Le tout dans un scollpane
          this.getContentPane().add(new JScrollPane(globalPanel));
       }
     
       public void actionPerformed(ActionEvent e)
       {
          //detection du bouton cliqué et envoi commande change panneau
          JComboBox cb = (JComboBox)e.getSource();
          String chaine = cb.getSelectedItem().toString();
     
          switch(Integer.parseInt(e.getActionCommand()))
          {
             case 1:
                ((ChangeAble)panelCbx1).setChange(chaine);
                break;
             case 2:
                ((ChangeAble)panelCbx2).setChange(chaine);
                break;
             case 3:
                ((ChangeAble)panelCbx3).setChange(chaine);
                break;
          }
       }
    }
     
    class JPanel1 extends JPanel implements ChangeAble
    {
       private JLabel changement;
       public JPanel1(String title)
       {
          setBorder(BorderFactory.createTitledBorder("Panneau de type Panel1"));
          setLayout(new BorderLayout());
          setBackground(new Color(210,210,210));
          changement = new JLabel("Rien dans mon panneau 1");
          this.add(new JLabel("Affichage des changements : "),BorderLayout.NORTH);
          this.add(changement,BorderLayout.CENTER);
       }
       public void setChange(String chaine)
       {
        changement.setText("Change="+chaine);  
       }
    }
    class JPanel2 extends JPanel implements ChangeAble
    {
       private JLabel changement;
       public JPanel2(String title)
       {
          setBorder(BorderFactory.createTitledBorder("Panneau de type Panel2"));
          setLayout(new BorderLayout());
          setBackground(new Color(190,190,190));
     
          changement = new JLabel("Rien dans mon panneau 2");
          this.add(new JLabel("Affichage des changements : "),BorderLayout.NORTH);
          this.add(changement,BorderLayout.CENTER);
       }
       public void setChange(String chaine)
       {
        changement.setText("Change="+chaine);  
       }
    }
    class JPanel3 extends JPanel implements ChangeAble
    {
       private JLabel changement;
       public JPanel3(String title)
       {
          setBorder(BorderFactory.createTitledBorder("Panneau de type Panel3"));
          setLayout(new BorderLayout());
          setBackground(new Color(230,230,230));
          changement = new JLabel("Rien dans mon panneau 3");
          this.add(new JLabel("Affichage des changements : "),BorderLayout.NORTH);
          this.add(changement,BorderLayout.CENTER);
       }
       public void setChange(String chaine)
       {
        changement.setText("Change="+chaine);  
       }
    }
     
    interface ChangeAble
    {
       public void setChange(String chaine);
    }
    la même que tout à l'heure avec 3 JPanel spécifiques.
    Evidemment il est mieux de créer chacune des classes dans des fichiers spécifiques.
    Pour éviter le swicth utilise une List de JPanel

    A++

  14. #14
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Non en prenant ton dernier exemple quand tu changes les valeurs d'une combo tu change de panel pas la valeur dans un panel. Car tout mes panels vont se superposer.Quand je change la valeur d'une combo ça m'ouvre un nouveau panel avec plein d'options dedans.




    Bon je galere depuis des plombes pour une connerie à la con encore et je trouve pas la rep dans la java doc. Comment mettre une valeur par defaut dans une combobox pour eviter que le premier choix de la combo s'affiche à l'ouverture de l'appli.

  15. #15
    Membre éprouvé
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut
    Last chance encore !
    c'est un mix des codes mis au dessus.
    un changement dans un combo affcihe le panneau qu'il faut avec la nouvelle valeur.

    Tu verras j'ai mis aussi une pré selection des items dans les combos au lancement.

    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
     
     
    public class Main extends JApplet implements ActionListener
    {
     
       private JPanel containerPane ;
       private JPanel panelCbx1;
       private JPanel panelCbx2;
       private JPanel panelCbx3;
     
       public void init()
       {
          JPanel globalPanel = new JPanel();
          globalPanel.setLayout(new BorderLayout());
     
          //3 COMBOS
          JComboBox jComboBox1=new JComboBox(new Object[]{"cb1 A"  ,"cb1 B"  ,"cb1 C"});
          JComboBox jComboBox2=new JComboBox(new Object[]{"cb2 AA" ,"cb2 BB" ,"cb2 CC"});
          JComboBox jComboBox3=new JComboBox(new Object[]{"cb3 AAA","cb3 BBB","cb3 CCC"});
     
          JPanel panelNord = new JPanel();
          panelNord.setLayout(new FlowLayout(FlowLayout.LEFT,5,5));
     
          //Pre selection dans un combo 2 facon pour index ... 
          jComboBox1.setSelectedIndex(0);
          jComboBox2.setSelectedIndex(1);
          // ... ou par item
          jComboBox3.setSelectedItem("cb3 CCC");
     
          //pour lancer actionPerformed apres clic dessus
          jComboBox1.addActionListener(this);
          jComboBox2.addActionListener(this);
          jComboBox3.addActionListener(this);
          //retrouver d'ou vient l'action
          jComboBox1.setActionCommand("1");
          jComboBox2.setActionCommand("2");
          jComboBox3.setActionCommand("3");
     
          panelNord.add(jComboBox1);
          panelNord.add(jComboBox2);
          panelNord.add(jComboBox3);
     
          containerPane = new JPanel();
          containerPane.setBorder(BorderFactory.createTitledBorder("Pannneau changeant"));
          containerPane.setLayout(new BorderLayout(3,1));
     
          panelCbx1 = new JPanel1("rien de neuf pour cb1");
          panelCbx2 = new JPanel2("rien de neuf pour cb2");
          panelCbx3 = new JPanel3("rien de neuf pour cb3");
     
          containerPane.add(panelCbx1);
     
          globalPanel.add(panelNord,BorderLayout.NORTH);
          globalPanel.add(containerPane,BorderLayout.CENTER);
          //Le tout dans un scollpane
          this.getContentPane().add(new JScrollPane(globalPanel));
       }
     
       public void actionPerformed(ActionEvent e)
       {
          //detection du bouton cliqué et envoi commande change panneau
          JComboBox cb = (JComboBox)e.getSource();
          String chaine = cb.getSelectedItem().toString();
     
          switch(Integer.parseInt(e.getActionCommand()))
          {
             case 1:
                ((ChangeAble)panelCbx1).setChange(chaine);
                changePanel(1);
                break;
             case 2:
                ((ChangeAble)panelCbx2).setChange(chaine);
                changePanel(2);
                break;
             case 3:
                ((ChangeAble)panelCbx3).setChange(chaine);
                changePanel(3);
                break;
          }
       }
       public void changePanel(int index)
       {
          //Suppression du contenu
          containerPane.removeAll();
          //creation d'un nouveau contenu
          Component cp = null;
          switch(index)
          {
             case 1:
                cp=panelCbx1;
                break;
             case 2:
                cp=panelCbx2;
                break;
             case 3:
                cp=panelCbx3;
                break;
          }
          //Ajout et mise a jour
          containerPane.add(cp,BorderLayout.NORTH);
          containerPane.revalidate();
          containerPane.repaint();
       }
    }
     
    class JPanel1 extends JPanel implements ChangeAble
    {
       private JLabel changement;
       public JPanel1(String title)
       {
          setBorder(BorderFactory.createTitledBorder("Panneau de type Panel1"));
          setLayout(new BorderLayout());
          setBackground(new Color(210,210,210));
          changement = new JLabel("Rien dans mon panneau 1");
          this.add(new JLabel("Affichage des changements : "),BorderLayout.NORTH);
          this.add(changement,BorderLayout.CENTER);
       }
       public void setChange(String chaine)
       {
        changement.setText("Change="+chaine);  
       }
    }
    class JPanel2 extends JPanel implements ChangeAble
    {
       private JLabel changement;
       public JPanel2(String title)
       {
          setBorder(BorderFactory.createTitledBorder("Panneau de type Panel2"));
          setLayout(new BorderLayout());
          setBackground(new Color(190,190,190));
     
          changement = new JLabel("Rien dans mon panneau 2");
          this.add(new JLabel("Affichage des changements : "),BorderLayout.NORTH);
          this.add(changement,BorderLayout.CENTER);
       }
       public void setChange(String chaine)
       {
        changement.setText("Change="+chaine);  
       }
    }
    class JPanel3 extends JPanel implements ChangeAble
    {
       private JLabel changement;
       public JPanel3(String title)
       {
          setBorder(BorderFactory.createTitledBorder("Panneau de type Panel3"));
          setLayout(new BorderLayout());
          setBackground(new Color(230,230,230));
          changement = new JLabel("Rien dans mon panneau 3");
          this.add(new JLabel("Affichage des changements : "),BorderLayout.NORTH);
          this.add(changement,BorderLayout.CENTER);
       }
       public void setChange(String chaine)
       {
        changement.setText("Change="+chaine);  
       }
    }
     
    interface ChangeAble
    {
       public void setChange(String chaine);
    }
    A++

  16. #16
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Merci d'avoir pris autant de temps pour moi, tu m'as bien aidé.

  17. #17
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Comment faire pour creer une Jcombobox avec une valeur par défaut j'arrive pas à trouver...

  18. #18
    Membre éprouvé
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut
    Bah alors t'as vu mon p'tit bout de code ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
          //Pre selection dans un combo 2 facon pour index ... 
          jComboBox1.setSelectedIndex(0);
          jComboBox2.setSelectedIndex(1);
          // ... ou par item
          jComboBox3.setSelectedItem("cb3 CCC");
    Choisir une valeur par défaut revient à sélectionner une valeur d'un combobox soit par son index(setSelectedIndex(int index)) soit par une valeur déjà stockée dans son model (setSelectedItem(Object item))

    J'ai pas mieux ...
    A++

  19. #19
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2004
    Messages
    253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Haute Garonne (Midi Pyrénées)

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 253
    Par défaut
    Salut à tous,

    une solution pour afficher différents panels dans la meme zone: c'est d'utiliser un CardLayout. Et là, tu choisis le panel qui vient "au-dessus" des autres.

  20. #20
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    95
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 95
    Par défaut
    Je comprend pas ça ne fonctionne pas voici le code que j'ai pour mon jcombo:
    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
    private JComboBox getCombo1() {
    		if (combo1 == null) {
    			combo1 = new JComboBox();
     
    			combo1.setBounds(new Rectangle(17, 29, 135, 20));
    			combo1.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    			combo1.setEditor(new BasicComboBoxEditor());
    			combo1.setSelectedItem("parametres");
     
    			combo1.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					JComboBox jc = (JComboBox)e.getSource();
    					String chaine = jc.getSelectedItem().toString();
    					if(chaine=="Comptabilité"){
    						panelbasacc.setVisible(false);
     
    					}
    				}
    			});
    			combo1.addItem("Société");
    			combo1.addItem("Comptabilité");
     
     
    		}
    		return combo1;
    	}
    Le prog ne se lance pas si je fais le test sur societe mais fonctionne quand je le fait sur comptabilite.
    Et mon selecteditem ne fonctionne pas non plus!! Ca me saoul

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. énorme problème avec mon interface MFC
    Par cenedra dans le forum MFC
    Réponses: 23
    Dernier message: 17/07/2006, 09h36
  2. énorme problème avec mon interface MFC
    Par cenedra dans le forum C++
    Réponses: 2
    Dernier message: 12/07/2006, 09h54
  3. Repenser la structure de mon site
    Par SiM07 dans le forum Langage
    Réponses: 3
    Dernier message: 23/10/2005, 19h14
  4. Le JPanel est trop reduit pour mon interface !
    Par LeNeutrino dans le forum JBuilder
    Réponses: 4
    Dernier message: 25/07/2005, 18h58
  5. quel langage choisir pour mon interface graphique
    Par mrom34 dans le forum Langages de programmation
    Réponses: 6
    Dernier message: 09/03/2004, 19h12

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