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 :

JCombobox


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut JCombobox
    Bonjour,
    En fait voilà, j'ai créer un JTable dans lequel il y à quelques JCombobox, lorsque j'utilise ma JCombo, je rentre toute la JTable dans un tableau de String puis je fais apel à une methode me permettant de faire le total.
    Mon problème est le suivant:
    J'ai le choix dans ma JCombo ente "Vente" et "Reprise", mais quand je clique su la fleche de mon JCombo, ca me lance quand même ma methode. Au debu, je croyais avoir trouvé quelquechose avec getSelectedRow(), qui me renvoyait -1 si je cliquais sur la fleche au lieux d'un choix mais ca marche plus. J'espere avoir été assez clair, voici un bout de 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
     
    	AC.addActionListener(new ActionListener(){
     
    			public void actionPerformed(ActionEvent evenement){
     
    						f = 0;
    						System.out.println("ligne="+caisse.getSelectedRow());
     
    						//Calcul du nb de ligne utilisée
    						for(int i = 0;i<20;i++){
     
    							if(String.valueOf(caisse.getValueAt(i,7)).equalsIgnoreCase("VENTE")==true | String.valueOf(caisse.getValueAt(i,7)).equalsIgnoreCase("REPRISE")==true)
    								f++;
    						}
     
     
     
     
     
     
    						if(String.valueOf(AC.getSelectedItem()).equalsIgnoreCase("VENTE")==true & caisse.getSelectedRow()>=0){
     
     
    							//System.out.println("rentre ds :"+AC.getSelectedItem());
    							String[][] tab = new String[f][10];
    							for(int c = 0;c<f;c++){
     
    							tab[c][0] = String.valueOf(caisse.getValueAt(c,0));
    							tab[c][1] = String.valueOf(caisse.getValueAt(c,1));
    							tab[c][2] = String.valueOf(caisse.getValueAt(c,2));
    							tab[c][3] = String.valueOf(caisse.getValueAt(c,3));
    							tab[c][4] = String.valueOf(caisse.getValueAt(c,4));
    							tab[c][5] = String.valueOf(caisse.getValueAt(c,5));
    							tab[c][6] = String.valueOf(caisse.getValueAt(c,6));
    							tab[c][7] = String.valueOf(caisse.getValueAt(c,7));
    							tab[c][8] = String.valueOf(caisse.getValueAt(c,8));
    							tab[c][9] = String.valueOf(caisse.getValueAt(c,9));
     
    							}
     
    							toto.setText(Valid_Vente.Ret_tot_vente(tab,f));
     
    						}
     
    						if(String.valueOf(AC.getSelectedItem()).equalsIgnoreCase("REPRISE")==true & caisse.getSelectedRow()>=0){
     
     
    							//System.out.println("rentre ds :"+AC.getSelectedItem());
    							String[][] tab = new String[f][10];
    							for(int c = 0;c<f;c++){
     
    							tab[c][0] = String.valueOf(caisse.getValueAt(c,0));
    							tab[c][1] = String.valueOf(caisse.getValueAt(c,1));
    							tab[c][2] = String.valueOf(caisse.getValueAt(c,2));
    							tab[c][3] = String.valueOf(caisse.getValueAt(c,3));
    							tab[c][4] = String.valueOf(caisse.getValueAt(c,4));
    							tab[c][5] = String.valueOf(caisse.getValueAt(c,5));
    							tab[c][6] = String.valueOf(caisse.getValueAt(c,6));
    							tab[c][7] = String.valueOf(caisse.getValueAt(c,7));
    							tab[c][8] = String.valueOf(caisse.getValueAt(c,8));
    							tab[c][9] = String.valueOf(caisse.getValueAt(c,9));
     
    							}
     
    							toto.setText(Valid_Vente.Ret_tot_vente(tab,f));
     
    						}
    		}
     
    		});
    Merci d'avance

  2. #2
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut
    En fait quand je clique sur reprise, il utilise la méthode avec le parametre Vente, c'est ca uq eje ne comprend pas. Il faut que je reclique une fois sur le Combo(Quand il est sur reprise) pour qu il me lance la methode avec le parametre Reprise.

  3. #3
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut
    Re
    J'ai modifié le code pour que ca soit plus simple:
    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
     
    AC.addActionListener(new ActionListener(){
     
             public void actionPerformed(ActionEvent evenement){
     
                      f = 0;
                      System.out.println("ligne="+caisse.getSelectedRow());
     
                      //Calcul du nb de ligne utilisée
                      for(int i = 0;i<20;i++){
     
                         if(AC.getSelectedIndex()==0 | AC.getSelectedIndex()==1)
                       	  f++;
                      }
     
     
     
     
                      if(AC.getSelectedIndex()==0 | AC.getSelectedIndex()==1){
     
     
     
                         String[][] tab = new String[f][10];
                         for(int c = 0;c<f;c++){
     
                         tab[c][0] = String.valueOf(caisse.getValueAt(c,0));
                         tab[c][1] = String.valueOf(caisse.getValueAt(c,1));
                         tab[c][2] = String.valueOf(caisse.getValueAt(c,2));
                         tab[c][3] = String.valueOf(caisse.getValueAt(c,3));
                         tab[c][4] = String.valueOf(caisse.getValueAt(c,4));
                         tab[c][5] = String.valueOf(caisse.getValueAt(c,5));
                         tab[c][6] = String.valueOf(caisse.getValueAt(c,6));
                         tab[c][7] = String.valueOf(caisse.getValueAt(c,7));
                         tab[c][8] = String.valueOf(caisse.getValueAt(c,8));
                         tab[c][9] = String.valueOf(caisse.getValueAt(c,9));
     
                         }
     
                         toto.setText(Valid_Vente.Ret_tot_vente(tab,f));
     
                      }
    	}
     
    		});
    Mais toujours le même probleme,il faut à chaque fois que je clique 2 fois sur un élément de la JCombo afin de lance la methode,je comprend pas

  4. #4
    Membre chevronné Avatar de let_me_in
    Inscrit en
    Mai 2005
    Messages
    441
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 441
    Par défaut
    salut nicotine002,
    bon pour commencer, il faut etre un peu plus clair (AC est un combobox)..
    pour ton probleme, essaye avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    AC.addItemListener(new ItemListener(){
    public void itemStateChanged(ItemEvent e) {
    //ton travail
    }
     
    });
    jamias teste, mais esperons que ca marche

  5. #5
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut
    Il me génere une erreur à la compilation:
    "is not abstract and does not override abstract method actionPerformed"

  6. #6
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut
    Non excuse moi j'avais pas bien implémenter tn code j réessaie.

  7. #7
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut
    C'est bizarre, cette fois ci, je n ai plus besoin de cliquer 2 fois sur un des choix de la JCombobox mais quand il apelle la methode, ca fait l'inverse.Si je choisis Vente, ca envoie la methode avec Reprise et vice versa.

  8. #8
    Membre chevronné Avatar de let_me_in
    Inscrit en
    Mai 2005
    Messages
    441
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 441
    Par défaut
    montre le code?(juste le necessaire)

  9. #9
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut
    Voilà le code. Le but de ce code est donc de calculer un total à partir d'une JTable contenant des JComboBox(que j'ai creé grace à un TableModel).
    AC en fait c'est le nom de toute mes JCombobox de la colonne 7.
    Je suis sûr que la methode Ret_tot_vente(tab,f) que j'ai creer fonctionne bien(elle prend un tableau de String et genere le total en fonction des éléments choisis).

    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
     
    AC.addItemListener(new ItemListener(){
    			public void itemStateChanged(ItemEvent e) { 
     
                       f = 0;
     
                      //Calcul du nb de ligne utilisée
                      for(int i = 0;i<20;i++){
     
                         if(AC.getSelectedIndex()==0 | AC.getSelectedIndex()==1)
                       	  f++;
                      }
     
     
     
     
     
     
     
     
                     if(AC.getSelectedIndex()==0 | AC.getSelectedIndex()==1) {
     
     
     
     
                         String[][] tab = new String[f][10];
                         for(int c = 0;c<f;c++){
     
                         tab[c][0] = String.valueOf(caisse.getValueAt(c,0));
                         tab[c][1] = String.valueOf(caisse.getValueAt(c,1));
                         tab[c][2] = String.valueOf(caisse.getValueAt(c,2));
                         tab[c][3] = String.valueOf(caisse.getValueAt(c,3));
                         tab[c][4] = String.valueOf(caisse.getValueAt(c,4));
                         tab[c][5] = String.valueOf(caisse.getValueAt(c,5));
                         tab[c][6] = String.valueOf(caisse.getValueAt(c,6));
                         tab[c][7] = String.valueOf(caisse.getValueAt(c,7));
                         tab[c][8] = String.valueOf(caisse.getValueAt(c,8));
                         tab[c][9] = String.valueOf(caisse.getValueAt(c,9));
     
                         }
     
                         toto.setText(Ret_tot_vente(tab,f));
     
                     }
    	}
     
     
     
    		});
    Donc quand je selectionne REPRISE par exemple, ca envoie le parametre VENTE dans la methode
    Et si je rajoute des lignes au JTable et que je choisis un des choix, ca à l'air de me faire n'importe quoi,je desespere un peu

  10. #10
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut
    En fait je viens de remarquer que à chaque fois c'est le dernier JComboBox de mon JTable qui me fait cette erreur.Par exemple j'insere 3 lignes dans mon JTable et ben ca sera le JCombo de la 3ieme ligne qui va deconner.
    Exemple:
    1iere Ligne du JTable "Vente"
    2ieme Ligne du JTable "Vente"
    3ieme Ligne du JTable "Vente"

    ceci va envoyer a ma methode le calcul de "Vente","Vente","Reprise".

  11. #11
    Membre éclairé Avatar de nicotine002
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 577
    Par défaut
    Re Bonjour, j'en suis toujours au même point

    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
     
     
    AC.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent evenement) { 
     
                       f = 0;
     
                      //Calcul du nb de ligne utilisée
                      for(int i = 0;i<20;i++){
     
                         if(AC.getSelectedIndex()==0 | AC.getSelectedIndex()==1)
                       	  f++;
                      }
     
     
     
     
     
                    // if(AC.getSelectedIndex()==0 | AC.getSelectedIndex()==1) {
     
     
     
     
                         String[][] tab = new String[f][10];
                         for(int c = 0;c<f;c++){
     
                         tab[c][0] = String.valueOf(caisse.getValueAt(c,0));
                         tab[c][1] = String.valueOf(caisse.getValueAt(c,1));
                         tab[c][2] = String.valueOf(caisse.getValueAt(c,2));
                         tab[c][3] = String.valueOf(caisse.getValueAt(c,3));
                         tab[c][4] = String.valueOf(caisse.getValueAt(c,4));
                         tab[c][5] = String.valueOf(caisse.getValueAt(c,5));
                         tab[c][6] = String.valueOf(caisse.getValueAt(c,6));
                         tab[c][7] = String.valueOf(caisse.getValueAt(c,7));
                         tab[c][8] = String.valueOf(caisse.getValueAt(c,8));
                         tab[c][9] = String.valueOf(caisse.getValueAt(c,9));
     
                         }
     
                         toto.setText(Ret_tot_vente(tab,f));
     
     
    			}
     
     
     
    		});
    Je dois cliquer 2 fois sur le JComboBox pour que le JLabel s'actualise, je comprend vraiment pas pourquoi.C'est a dire que je fais mon choix et ensuite je reclique sur la JCombobox pour que le JLabel s'affiche, pourquoi?

    Merci d'avance

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

Discussions similaires

  1. [JComboBox] Mmise à jour contenu
    Par java_math dans le forum Composants
    Réponses: 4
    Dernier message: 16/07/2008, 18h27
  2. JComboBox action
    Par calypso dans le forum Composants
    Réponses: 4
    Dernier message: 02/08/2004, 15h41
  3. [jcombobox]l'élément affiché lié à un autre objet
    Par szdavid dans le forum Composants
    Réponses: 3
    Dernier message: 11/05/2004, 10h17
  4. [swing][JComboBox]Problème de taille
    Par n!co dans le forum Composants
    Réponses: 8
    Dernier message: 06/03/2004, 10h53
  5. Couleur d'une JComboBox disabled
    Par ced dans le forum Composants
    Réponses: 6
    Dernier message: 06/01/2004, 15h33

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