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 :

Problème avec des Boutons Radio


Sujet :

AWT/Swing Java

  1. #1
    Membre habitué Avatar de Spinoza23
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    328
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 328
    Points : 166
    Points
    166
    Par défaut
    Mon problème est le suivant... J'ais un groupe de bouton Radion qui suivant le bouton selectionné affiche une autre liste juste a coté d'autres boutons radio. Je n'arrive pas a rafraichir mon affichage. Je vous montre le code pour mieux m'expliquer

    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
            // Associate the two buttons with a button group
            ButtonGroup group = new ButtonGroup();
            group.add(_b1);
            group.add(_b2);
            group.add(_b3);
            group.add(_b4);
            group.add(_b5);
            _jpfonct.add(_b1);
            _jpfonct.add(_b2);
            _jpfonct.add(_b3);
            _jpfonct.add(_b4);
            _jpfonct.add(_b5);
            _b1.addActionListener(this);
            _b2.addActionListener(this);
            _b3.addActionListener(this);
            _b4.addActionListener(this);
            _b5.addActionListener(this);
    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
        public void actionPerformed(ActionEvent e)
        {
            if (_b1.equals(e.getSource()))
            {
                _panelfonct=_init;
                _panelfonct.repaint();
                _nom = "Arithmétique";
                JRadioButton b1 = new JRadioButton("Addition");
                JRadioButton b2 = new JRadioButton("Soustraction");
                JRadioButton b3 = new JRadioButton("Multiplication");
                JRadioButton b4 = new JRadioButton("Division");
                JRadioButton b5 = new JRadioButton("Arrondi");
                JRadioButton b6 = new JRadioButton("Partie Entière");
                JRadioButton b7 = new JRadioButton("Entier supérieur");
                JRadioButton b8 = new JRadioButton("Valeur Absolue");
                JRadioButton b9 = new JRadioButton("Signe");
                JRadioButton b10 = new JRadioButton("Puissance");
                JRadioButton b11 = new JRadioButton("Modulo");
                JRadioButton b12 = new JRadioButton("Racine Carrée");
                _panelfonct.setLayout(new GridLayout(12,1));
                ButtonGroup group1 = new ButtonGroup();
                group1.add(b1);
                group1.add(b2);
                group1.add(b3);
                group1.add(b4);
                group1.add(b5);
                group1.add(b6);
                group1.add(b7);
                group1.add(b8);
                group1.add(b9);
                group1.add(b10);
                group1.add(b11);
                group1.add(b12);
                _panelfonct.add(b1);
                _panelfonct.add(b2);
                _panelfonct.add(b3);
                _panelfonct.add(b4);
                _panelfonct.add(b6);
                _panelfonct.add(b7);
                _panelfonct.add(b8);
                _panelfonct.add(b9);
                _panelfonct.add(b10);
                _panelfonct.add(b11);
                _panelfonct.add(b12);
                _jpnom.add(_panelfonct);
            }
     
            else if (_b2.equals(e.getSource()))
            {
                _panelfonct=_init;
                _panelfonct.repaint();
                _nom = "Texte";
                JRadioButton b1 = new JRadioButton("Concaténation");
                JRadioButton b2 = new JRadioButton("Longueur");
                JRadioButton b3 = new JRadioButton("Extraction");
                JRadioButton b4 = new JRadioButton("Position");
                JRadioButton b5 = new JRadioButton("Suppression des espaces à gauche");
                JRadioButton b6 = new JRadioButton("Suppression des espaces à droite");
                _panelfonct.setLayout(new GridLayout(6,1));
                ButtonGroup group1 = new ButtonGroup();
                group1.add(b1);
                group1.add(b2);
                group1.add(b3);
                group1.add(b4);
                group1.add(b5);
                group1.add(b6);
                _panelfonct.add(b1);
                _panelfonct.add(b2);
                _panelfonct.add(b3);
                _panelfonct.add(b4);
                _panelfonct.add(b6);
                _jpnom.add(_panelfonct);            
            }
     
            else if (_b3.equals(e.getSource()))
            {
                _panelfonct=_init;
                _panelfonct.repaint();
                _nom = "Conversion";
                JRadioButton b1 = new JRadioButton("Majuscule");
                JRadioButton b2 = new JRadioButton("Minuscule");
                JRadioButton b3 = new JRadioButton("Texte");
                JRadioButton b4 = new JRadioButton("Numérique");
                JRadioButton b5 = new JRadioButton("Code ASCII en caractère");
                JRadioButton b6 = new JRadioButton("Caractère en code ASCII");
                _panelfonct.setLayout(new GridLayout(6,1));
                ButtonGroup group1 = new ButtonGroup();
                group1.add(b1);
                group1.add(b2);
                group1.add(b3);
                group1.add(b4);
                group1.add(b5);
                group1.add(b6);
                _panelfonct.add(b1);
                _panelfonct.add(b2);
                _panelfonct.add(b3);
                _panelfonct.add(b4);
                _panelfonct.add(b6);
                _jpnom.add(_panelfonct);            
            }
     
            else if (_b4.equals(e.getSource()))
            {
                _panelfonct=_init;
                _panelfonct.repaint();
                _nom = "Conditionnelle";
                JRadioButton b1 = new JRadioButton("Condition sur NULL");
                JRadioButton b2 = new JRadioButton("Première valeur non NULL" +
                                                   "(Nombre de valeur **)");
                JRadioButton b3 = new JRadioButton("Dans le cas" +
                                                   "(Nombre de cas **)");
                _panelfonct.setLayout(new GridLayout(5,1));
                ButtonGroup group1 = new ButtonGroup();
                group1.add(b1);
                group1.add(b2);
                group1.add(b3);
                _panelfonct.add(b1);
                _panelfonct.add(b2);
                _panelfonct.add(b3);
                _jpnom.add(_panelfonct);            
            }
     
            else if (_b5.equals(e.getSource()))
            {
                _panelfonct=_init;
                _panelfonct.repaint();
                _nom = "Groupe";
                JRadioButton b1 = new JRadioButton("Moyenne");
                JRadioButton b2 = new JRadioButton("Somme");
                JRadioButton b3 = new JRadioButton("Minimum");
                JRadioButton b4 = new JRadioButton("Maximum");
                JRadioButton b5 = new JRadioButton("Nombre");
                JRadioButton b6 = new JRadioButton("Nombre Distinct");
                _panelfonct.setLayout(new GridLayout(6,1));
                ButtonGroup group1 = new ButtonGroup();
                group1.add(b1);
                group1.add(b2);
                group1.add(b3);
                group1.add(b4);
                group1.add(b5);
                group1.add(b6);
                _panelfonct.add(b1);
                _panelfonct.add(b2);
                _panelfonct.add(b3);
                _panelfonct.add(b4);
                _panelfonct.add(b6);
                _jpnom.add(_panelfonct);            
            }
        }

    Si quelqu'un peut m'aider, son aide sera le bien venu... D'avance Merci

    Avec ce code, j'ais en fait les boutons radio qui s'ajoute dans mon panel au fur et a mesure... Il ne s'effacent plus... admetons que j'ais 2 boutons radio : arithmétique et texte. lorsque je clique sur arithmétique, je voi a coté apparaitre des boutons radio comme addition, soustraction, ... Je clique alors sur le bouton radio texte... et cette foi ci je devrais voir : concaténation, longueur, ... hors je vois tous les radio d'arithmétique + tous les radio de texte... j'espère que vous comprenez mieux ce que je veux dire...
    Java c'est pas de la menthe a l'eau
    Et n'oubliez pas : Ne pas respirer tue...
    Mon BLOOOUUUG Un site trop bien

    Pour la recherche JAVA des liens pratiques :
    GOOGLE LA JAVADOC LES FAQ LES ARCHIVES

  2. #2
    Membre régulier Avatar de mattyeux
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2006
    Messages
    169
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2006
    Messages : 169
    Points : 101
    Points
    101
    Par défaut
    Je sais pas quelle but a ton appli et si les solutions que je vais te proposer te conviendront mais voila comment je ferai. Ce ne sont certainement pas les meilleures solutions (je ne suis pas un "javateux").

    -Je pense (je n'ai pas vérifié) qu'il doit y avoir des méthodes permettant de vider un JPanel (ou panel selon ce que tu as utilisé). Je sais pas vraiment ce que fait ta ligne "_panelfonct=_init;". A chaque fois que tu cliques sur un bouton, tu vides le JPanel et tu réaffiche ce que tu veux. Va voir peut être du coté de JComponent .. ?

    -sinon tu peux utiliser des JPanel différents au lieu d'utiliser le même à chaque fois (ce la dépend aussi de ce que tu souhaites faire). Tu les destroy et les recréer. A chaque fois, mais ca devient vite pas beau ....

    -Pour mois la meilleure solution (dans le cas où l'utilisateur est amené souvent à cliquer sur les boutons; c'est de construire tous tes JPanels ou tu mets tes Boutons Radios, et après tu rends visible que celui qui t'intéresses et tu rends les autres "invisibles"....

    Je pense que dans ton cas, c'est à la première solution qui t'intéresses

  3. #3
    Membre habitué Avatar de Spinoza23
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    328
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 328
    Points : 166
    Points
    166
    Par défaut
    J'ais réussi a m'en sortir !!!!

    Voici a quoi ressemble le code :

    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
        private JRadioButton _b1 = new JRadioButton("Arithmétiques");
        private JRadioButton _b2 = new JRadioButton("Textes");
        private JRadioButton _b3 = new JRadioButton("Conversions");
        private JRadioButton _b4 = new JRadioButton("Conditions");
        private JRadioButton _b5 = new JRadioButton("Groupes");
     
        private JRadioButton _bV1 = new JRadioButton("Constante");
        private JRadioButton _bV2 = new JRadioButton("Informations");
        private JRadioButton _bV3 = new JRadioButton("Informations calculées");
        private JRadioButton _bV4 = new JRadioButton("Champ ou variable");
     
        private JTabbedPane _criteriacontainer = new JTabbedPane();
     
        private CardLayout mo_cardLayout;
     
        private JPanel _jpfonct  = new JPanel(new GridLayout(5,1));
        private JPanel _jpgen    = new JPanel();
        private JPanel _jpnom    = new JPanel();
        private JPanel _jptype   = new JPanel(new GridLayout(4,1));
        private JPanel _jpgenval = new JPanel();
        private JPanel _jptree   = new JPanel();
        private JPanel _jpexpre  = new JPanel();
        private JPanel _jpinfo   = new JPanel();
     
        private String _nom;
        private TitledBorder _border;
     
        private void initPanel()
        {
            mo_cardLayout = new CardLayout();
            _jpnom = new JPanel (mo_cardLayout);
     
            ButtonGroup group = new ButtonGroup();
            group.add(_b1);
            group.add(_b2);
            group.add(_b3);
            group.add(_b4);
            group.add(_b5);
            _jpfonct.add(_b1);
            _jpfonct.add(_b2);
            _jpfonct.add(_b3);
            _jpfonct.add(_b4);
            _jpfonct.add(_b5);
            _b1.addActionListener(this);
            _b2.addActionListener(this);
            _b3.addActionListener(this);
            _b4.addActionListener(this);
            _b5.addActionListener(this);
     
            JPanel _panelinit = new JPanel();
     
            JRadioButton bA1 = new JRadioButton("Addition");
            JRadioButton bA2 = new JRadioButton("Soustraction");
            JRadioButton bA3 = new JRadioButton("Multiplication");
            JRadioButton bA4 = new JRadioButton("Division");
            JRadioButton bA5 = new JRadioButton("Arrondi");
            JRadioButton bA6 = new JRadioButton("Partie Entière");
            JRadioButton bA7 = new JRadioButton("Entier supérieur");
            JRadioButton bA8 = new JRadioButton("Valeur Absolue");
            JRadioButton bA9 = new JRadioButton("Signe");
            JRadioButton bA10 = new JRadioButton("Puissance");
            JRadioButton bA11 = new JRadioButton("Modulo");
            JRadioButton bA12 = new JRadioButton("Racine Carrée");
            JPanel _panelarithmetique = new JPanel();
            _panelarithmetique.setLayout(new GridLayout(12,1));
            ButtonGroup groupA = new ButtonGroup();
            groupA.add(bA1);
            groupA.add(bA2);
            groupA.add(bA3);
            groupA.add(bA4);
            groupA.add(bA5);
            groupA.add(bA6);
            groupA.add(bA7);
            groupA.add(bA8);
            groupA.add(bA9);
            groupA.add(bA10);
            groupA.add(bA11);
            groupA.add(bA12);
            _panelarithmetique.add(bA1);
            _panelarithmetique.add(bA2);
            _panelarithmetique.add(bA3);
            _panelarithmetique.add(bA4);
            _panelarithmetique.add(bA5);
            _panelarithmetique.add(bA6);
            _panelarithmetique.add(bA7);
            _panelarithmetique.add(bA8);
            _panelarithmetique.add(bA9);
            _panelarithmetique.add(bA10);
            _panelarithmetique.add(bA11);
            _panelarithmetique.add(bA12);
     
            JRadioButton bT1 = new JRadioButton("Concaténation");
            JRadioButton bT2 = new JRadioButton("Longueur");
            JRadioButton bT3 = new JRadioButton("Extraction");
            JRadioButton bT4 = new JRadioButton("Position");
            JRadioButton bT5 = new JRadioButton("Suppression des espaces à gauche");
            JRadioButton bT6 = new JRadioButton("Suppression des espaces à droite");
            JPanel _paneltexte = new JPanel();
            _paneltexte.setLayout(new GridLayout(6,1));
            ButtonGroup groupT = new ButtonGroup();
            groupT.add(bT1);
            groupT.add(bT2);
            groupT.add(bT3);
            groupT.add(bT4);
            groupT.add(bT5);
            groupT.add(bT6);
            _paneltexte.add(bT1);
            _paneltexte.add(bT2);
            _paneltexte.add(bT3);
            _paneltexte.add(bT4);
            _paneltexte.add(bT5);
            _paneltexte.add(bT6);
     
            JRadioButton bC1 = new JRadioButton("Majuscule");
            JRadioButton bC2 = new JRadioButton("Minuscule");
            JRadioButton bC3 = new JRadioButton("Texte");
            JRadioButton bC4 = new JRadioButton("Numérique");
            JRadioButton bC5 = new JRadioButton("Code ASCII en caractère");
            JRadioButton bC6 = new JRadioButton("Caractère en code ASCII");
            JPanel _panelconversion = new JPanel();
            _panelconversion.setLayout(new GridLayout(6,1));
            ButtonGroup groupC = new ButtonGroup();
            groupC.add(bC1);
            groupC.add(bC2);
            groupC.add(bC3);
            groupC.add(bC4);
            groupC.add(bC5);
            groupC.add(bC6);
            _panelconversion.add(bC1);
            _panelconversion.add(bC2);
            _panelconversion.add(bC3);
            _panelconversion.add(bC4);
            _panelconversion.add(bC5);
            _panelconversion.add(bC6);    
     
            JRadioButton bCd1 = new JRadioButton("Condition sur NULL");
            JRadioButton bCd2 = new JRadioButton("Première valeur non NULL ");
    //      "(Nombre de valeur **)");
            String[] data = {"1", "2", "3", "4"};
            JComboBox nbval = new JComboBox(data);                                          
            JRadioButton bCd3 = new JRadioButton("Dans le cas");
    //      "(Nombre de cas **)");
            String[] data1 = {"1", "2", "3", "4"};
            JComboBox nbcase = new JComboBox(data1);
            JPanel _panelcondition = new JPanel();
            _panelcondition.setLayout(new GridLayout(3,1));
            ButtonGroup groupCd = new ButtonGroup();
            groupCd.add(bCd1);
            groupCd.add(bCd2);
            groupCd.add(bCd3);
            _panelcondition.add(bCd1);
            _panelcondition.add(bCd2);
    //        _panelcondition.add(ColorChooser);
            _panelcondition.add(nbval);
            _panelcondition.add(bCd3);
            _panelcondition.add(nbcase);
     
            JRadioButton bG1 = new JRadioButton("Moyenne");
            JRadioButton bG2 = new JRadioButton("Somme");
            JRadioButton bG3 = new JRadioButton("Minimum");
            JRadioButton bG4 = new JRadioButton("Maximum");
            JRadioButton bG5 = new JRadioButton("Nombre");
            JRadioButton bG6 = new JRadioButton("Nombre Distinct");
            JPanel _panelgroupe = new JPanel();
            _panelgroupe.setLayout(new GridLayout(6,1));
            ButtonGroup groupG = new ButtonGroup();
            groupG.add(bG1);
            groupG.add(bG2);
            groupG.add(bG3);
            groupG.add(bG4);
            groupG.add(bG5);
            groupG.add(bG6);
            _panelgroupe.add(bG1);
            _panelgroupe.add(bG2);
            _panelgroupe.add(bG3);
            _panelgroupe.add(bG4);
            _panelgroupe.add(bG5);
            _panelgroupe.add(bG6);
     
            _jpnom.add (_panelinit,"Init");
            _jpnom.add (_panelarithmetique,"Arithmétique");
            _jpnom.add (_paneltexte,"Texte");
            _jpnom.add (_panelconversion,"Conversion");
            _jpnom.add (_panelcondition,"Conditionnelle");
            _jpnom.add (_panelgroupe,"Groupe");
     
            // Création du panneau
            _jpexpre.setBorder(new TitledBorder(new EtchedBorder(),
                    "Expression de la fonction :",
                    TitledBorder.LEFT,
                    TitledBorder.TOP,
                    _jpexpre.getFont().deriveFont(Font.ITALIC, 12),
                    Color.black));
            _jpexpre.setPreferredSize(new Dimension(690,100));
     
            JTextArea expression = new JTextArea();
            expression.setPreferredSize(new Dimension(680,90));
            _jpexpre.add(expression, BorderLayout.CENTER);
     
            _jpgen.add(_jpexpre,BorderLayout.SOUTH);
            _jpgen.add(_jpfonct,BorderLayout.WEST);
            _jpgen.add(_jpnom,BorderLayout.CENTER);
     
            _expressionpanel.add(_jpgen);
    Java c'est pas de la menthe a l'eau
    Et n'oubliez pas : Ne pas respirer tue...
    Mon BLOOOUUUG Un site trop bien

    Pour la recherche JAVA des liens pratiques :
    GOOGLE LA JAVADOC LES FAQ LES ARCHIVES

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Select activable avec des boutons radio (IE :S)
    Par Fabthebug dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 25/09/2009, 15h49
  2. Récupération d'information avec des boutons radio
    Par fred19732 dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 10/05/2009, 20h23
  3. Problème avec un bouton radio obligatoire
    Par flab78 dans le forum Langage
    Réponses: 3
    Dernier message: 24/06/2008, 15h42
  4. Problème avec un bouton radio
    Par bonnet85 dans le forum Langage
    Réponses: 1
    Dernier message: 10/02/2008, 13h03
  5. problème avec des boutons
    Par Sylar44 dans le forum Interfaces Graphiques en Java
    Réponses: 10
    Dernier message: 10/11/2007, 15h01

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