Remplir un TextField en Fonction D'une ComboBox

Résolu
sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011 - 30 août 2010 à 14:29
cs_croire Messages postés 20 Date d'inscription lundi 2 août 2010 Statut Membre Dernière intervention 22 mai 2012 - 22 mai 2012 à 15:31
Bonjour à tous,j'ai besoin d'un petit coup de pousse;

Lorsque je sélectionne une valeur d'Une ComboBox je n'arriver pas à afficher le resultat ce cette valeur à partir d'une Base Données SqlServer 2005 dans TextField (Mon Mini Projet est en Java Eclipse et SQL Server2005)


Merci D'Avance
A voir également:

24 réponses

sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011
2 sept. 2010 à 12:58
En fin Trouver!!
!


Merci bcp bcp bcp; j'espère de retrouver bientôt avec un nouveau problématique. Au faite !! Vous avez commis une petite faute dans ce dernier code.

 private void fillTextField(String value) {
 
 try{
    String s = "select libelle from EtatMateriel where RefEtat='" + value + "'";
    Statement st=Accueil.con.createStatement();
    ResultSet rst=st.executeQuery(s);
    if(rst.next()){
      getT1().setText(rst.getString("libelle"));
    } else
      System.err.println("No first value found :/");
 }
 catch (SQLException e) {	
e.printStackTrace();
}

  }


3
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
31 août 2010 à 11:21
Salut,

C'est quoi que tu cherches à faire exactement ?
Remplir un champ texte avec la valeur sélectionnée dans ton combobox ?
Remplir un champ texte avec la valeur trouvée dans une db en utilisant la valeur sélectionnée dans ton combobox ?


Code d'exemple :
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Test extends JFrame implements ActionListener {
private JComboBox			comboBox			= null;
private JTextField			textField			= null;

public static void main(final String[] args) {
new Test().setVisible(true);
}

public Test() {
final JPanel panel = new JPanel();
panel.add(getComboBox());
panel.add(getTextField());
setContentPane(panel);
getComboBox().setSelectedIndex(0);// pas oblige
setDefaultCloseOperation(3);
pack();
setLocationRelativeTo(null);
}

private JComboBox getComboBox() {
if (comboBox == null) {
comboBox = new JComboBox();
final DefaultComboBoxModel model = new DefaultComboBoxModel();
for (int i = 1; i < 11; ++i)
model.addElement("Item " + i);
comboBox.setModel(model);
comboBox.setPreferredSize(new Dimension(150, 20));
comboBox.addActionListener(this);
}
return comboBox;
}

private JTextField getTextField() {
if (textField == null) {
textField = new JTextField();
textField.setPreferredSize(new Dimension(150, 20));
}
return textField;
}

private void fillTextField(String value) {
// cas 1
getTextField().setText(value);
// cas 2
//recherche dans la db de la donnée que tu veux
//......
}

public void actionPerformed(final ActionEvent e) {
final Object o = e.getSource();
if (o.equals(getComboBox())) {
fillTextField("" + getComboBox().getSelectedItem());
}
}
}





------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

OoWORAoO
0
Kidator Messages postés 16 Date d'inscription dimanche 6 juin 2010 Statut Membre Dernière intervention 31 août 2010
31 août 2010 à 16:09
Salut,

je ne sais pas sql mais regarde ce lien :

http://www.javafr.com/forum/sujet-REMPLIR-COMBOBOX-PARTIR-BASE-DONNEE_1254650.aspx

Bonne chance!

Kidator.
0
sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011
31 août 2010 à 20:07
Merci Bcp pour ces reponses;
Mais ça n'a pas marché votre code Mr. Twinuts
Au faite!! c'est " Remplir un champ texte avec la valeur trouvée dans une db en utilisant la valeur sélectionnée dans ton combobox automatiquement va être afficher "
je doute au niveau de la methode "remplir_t1" et je ne sais pas ou je vais l'appeler pous qu'elle s'affiche automatiquement dans le TextField
Je vais vous montrer mon code:




import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JDesktopPane;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JComboBox;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.JTextPane;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JProgressBar;
import javax.swing.table.DefaultTableModel;

public class ModifierMat extends JFrame {


private static final long serialVersionUID = 1L;
private ResultSet rs;
private ResultSetMetaData rm;
private DefaultTableModel model;
private JPanel jContentPane = null;
private static Statement st;  //  @jve:decl-index=0:
private static JFrame jFrame;
private JDesktopPane jDesktopPane = null;
private static JComboBox jc = null;
private JLabel NumSerie_l = null;
private JLabel DateInstallation_l = null;
private JLabel Marque_l = null;
private JLabel Etat_l = null;
private JLabel Type_l = null;
private static JTextField DateInstallation_t = null;
private JButton quitter = null;
private JButton Modifier = null;
private JLabel Titre = null;
private static JComboBox jc2 = null;
private static JComboBox jc1 = null;
private static JComboBox jc3 = null;
private JTextField t1 = null;
private JTextField t2 = null;
private JTextField t3 = null;
/**
 * This is the default constructor
 */
public ModifierMat() {
super();
initialize();
}

/**
 * This method initializes this
 * 
 * @return void
 */
private void initialize() {
this.setSize(751, 486);
this.setContentPane(getJContentPane());
this.setTitle("Modifier Materiel");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}

/**
 * This method initializes jContentPane
 * 
 * @return javax.swing.JPanel
 */
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJDesktopPane(), BorderLayout.CENTER);
}
return jContentPane;
}


/**
 * This method initializes jDesktopPane	
 * 	
 * @return javax.swing.JDesktopPane	
 */
private JDesktopPane getJDesktopPane() {
if (jDesktopPane == null) {
Titre = new JLabel();
Titre.setBounds(new Rectangle(122, 40, 301, 47));
Titre.setFont(new Font("Footlight MT Light", Font.BOLD, 30));
Titre.setForeground(Color.white);
Titre.setText("  Modifier Materiel");
Type_l = new JLabel();
Type_l.setBounds(new Rectangle(29, 271, 172, 36));
Type_l.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
Type_l.setForeground(SystemColor.controlHighlight);
Type_l.setText(" Type Du Materiel");
Marque_l = new JLabel();
Marque_l.setBounds(new Rectangle(30, 315, 199, 34));
Marque_l.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
Marque_l.setForeground(SystemColor.controlHighlight);
Marque_l.setText(" Marque  Du Materiel");
Etat_l = new JLabel();
Etat_l.setBounds(new Rectangle(30, 223, 173, 36));
Etat_l.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
Etat_l.setForeground(SystemColor.controlHighlight);
Etat_l.setText(" Etat Du Materiel ");
DateInstallation_l = new JLabel();
DateInstallation_l.setBounds(new Rectangle(30, 167, 173, 30));
DateInstallation_l.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
DateInstallation_l.setForeground(SystemColor.controlHighlight);
DateInstallation_l.setText(" Date d'Installation");
NumSerie_l = new JLabel();
NumSerie_l.setBounds(new Rectangle(30, 121, 175, 30));
NumSerie_l.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
NumSerie_l.setForeground(SystemColor.controlHighlight);
NumSerie_l.setText(" Numéro De Serie");
jDesktopPane = new JDesktopPane();
jDesktopPane.setForeground(SystemColor.controlHighlight);
jDesktopPane.setBackground(SystemColor.activeCaption);
jDesktopPane.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
jDesktopPane.add(getJc(), null);
jDesktopPane.add(NumSerie_l, null);
jDesktopPane.add(DateInstallation_l, null);
jDesktopPane.add(Etat_l, null);
jDesktopPane.add(Marque_l, null);
jDesktopPane.add(Type_l, null);
jDesktopPane.add(getDateInstallation_t(), null);
jDesktopPane.add(getQuitter(), null);
jDesktopPane.add(getModifier(), null);
jDesktopPane.add(Titre, null);
jDesktopPane.add(getJc2(), null);
jDesktopPane.add(getJc1(), null);
jDesktopPane.add(getJc3(), null);
jDesktopPane.add(getT1(), null);
jDesktopPane.add(getT2(), null);
jDesktopPane.add(getT3(), null);
}
return jDesktopPane;
}

/*
------ Method de remplissage du jComboBox NumSerie -----*/ 

public void remplir_JCombo(){
 try {
String s="select NumSerie from Materiel";
Statement st=Accueil.con.createStatement();
ResultSet rst=st.executeQuery(s);


while(rst.next()){
jc.addItem( rst.getObject(1));
}


} catch (SQLException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
}
 
}

/*
------ Method de remplissage du jComboBox Etat -------*/ 

public void remplir_JComboEtat(){
 try {
String s="select RefEtat from EtatMateriel";
Statement st=Accueil.con.createStatement();
ResultSet rst=st.executeQuery(s);


while(rst.next()){
jc1.addItem( rst.getObject(1));
}


} catch (SQLException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
}
 
}


/*---- Method de remplissage du jComboBox Type ----*/ 

public void remplir_JComboType(){
 try {
String s="select RefType from TypeMateriel";
Statement st=Accueil.con.createStatement();
ResultSet rst=st.executeQuery(s);


while(rst.next()){
jc2.addItem( rst.getObject(1));
}


} catch (SQLException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
}
 
}

/*---- Method de remplissage du jComboBox Marque ----*/ 

public void remplir_JComboMarque(){
 try {
String s="select RefMarque from Marque";
Statement st=Accueil.con.createStatement();
ResultSet rst=st.executeQuery(s);


while(rst.next()){
jc3.addItem( rst.getObject(1));
}


} catch (SQLException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
}
 
}


/*------ Methode de Remplissage JTextField t1 ------*/
public static void remplir_t1(){
 
try {
if(jc1.getSelectedItem().toString()!=null){
String s="select libelle from EtatMateriel where RefEtat='"+(String)jc1.getSelectedItem()+"'";
Statement st=Accueil.con.createStatement();
ResultSet rst=st.executeQuery(s);



}
} catch (SQLException e) {
e.printStackTrace();
}
}


/*------Remplir ComboBox Numeros de series du Materiel -----*/

private JComboBox getJc() {
if (jc == null) {
jc = new JComboBox();
jc.setBounds(new Rectangle(288, 120, 235, 28));
remplir_JCombo();
add(jc);
}
return jc;
}

/**
 * This method initializes Nom_t	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getDateInstallation_t() {
if (DateInstallation_t == null) {
DateInstallation_t = new JTextField();
DateInstallation_t.setBounds(new Rectangle(288, 171, 236, 28));
}
return DateInstallation_t;
}
/*-------------  Modifier Materiel  -----------*/

public static void ModifMat(){
 
try {

st=Accueil.con.createStatement();
st.executeUpdate("update Materiel set DateInstallation='"+DateInstallation_t.getText()+"' ,RefEtat='"+jc1.getSelectedItem()+"' ,RefType='"+ jc2.getSelectedItem()+"' ,RefMarque='"+jc3.getSelectedItem()+"'  where NumSerie='"+jc.getSelectedItem().toString()+"'");
JOptionPane.showMessageDialog(jFrame, "Modification avec succés","Confirmation", JOptionPane.INFORMATION_MESSAGE, null);
st.close();

} catch (SQLException e) {
e.printStackTrace();
}
}


/**
 * This method initializes Modifier	
 * 	
 * @return javax.swing.JButton	
 */
public static void mouseClicked(MouseEvent event) {
    System.out.println("mouse clicked");
    }

private JButton getModifier() {
if (Modifier == null) {
Modifier = new JButton();
Modifier.setBounds(new Rectangle(396, 378, 97, 28));
Modifier.setForeground(SystemColor.activeCaption);
Modifier.setFont(new Font("Dialog", Font.BOLD, 14));
Modifier.setText("Modifier");
Modifier.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
ModifMat();
}
});
}
return Modifier;
}

/**
 * This method initializes jc2	
 * 	
 * @return javax.swing.JComboBox	
 */
private JComboBox getJc2() {
if (jc2 == null) {
jc2 = new JComboBox();
jc2.setBounds(new Rectangle(287, 269, 100, 28));
remplir_JComboType();
add(jc2);

}
return jc2;
}

/**
 * This method initializes jc1	
 * 	
 * @return javax.swing.JComboBox	
 */
private JComboBox getJc1() {
if (jc1 == null) {
jc1 = new JComboBox();
jc1.setBounds(new Rectangle(287, 222, 99, 29));
remplir_JComboEtat();
add(jc1);


}
return jc1;
}

/**
 * This method initializes jc3	
 * 	
 * @return javax.swing.JComboBox	
 */
private JComboBox getJc3() {
if (jc3 == null) {
jc3 = new JComboBox();
jc3.setBounds(new Rectangle(287, 316, 98, 27));
remplir_JComboMarque();
add(jc3);

}
return jc3;
}

/**
 * This method initializes t1	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getT1() {
if (t1 == null) {
t1 = new JTextField();
t1.setBounds(new Rectangle(388, 224, 136, 26));
t1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
remplir_t1();
add(t1);
}
});
}

return t1;
}

private void fillTextField(String value) {
getT1().setText(value);

}


public void actionPerformed(final ActionEvent e) {
final Object o = e.getSource();
if (o.equals(getJc1())) {
fillTextField("" + getJc1().getSelectedItem());
}
}



/**
 * This method initializes t2	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getT2() {
if (t2 == null) {
t2 = new JTextField();
t2.setBounds(new Rectangle(388, 270, 136, 27));
}
return t2;
}

/**
 * This method initializes t3	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getT3() {
if (t3 == null) {
t3 = new JTextField();
t3.setBounds(new Rectangle(386, 315, 138, 27));
}
return t3;
}

/**
 * This method initializes quitter	
 * 	
 * @return javax.swing.JButton	
 */
private JButton getQuitter() {
if (quitter == null) {
quitter = new JButton();
quitter.setBounds(new Rectangle(493, 378, 88, 28));
quitter.setForeground(SystemColor.activeCaption);
quitter.setFont(new Font("Dialog", Font.BOLD, 14));
quitter.setText("Quitter");
quitter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
mouseClicked(null);
dispose();
}
});
}
return quitter;
}
}

0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
1 sept. 2010 à 12:44
Salut,

Questions :
- Pourquoi tu n'ajoutes pas d'action listener sur le comboBox jc1 ??
- Meme si tu ajoutes le listener au combo tel qu'est ton code ça ne fonctionnera jamais.

Personnellement en regardant les fautes que tu fais dans ton code j'en déduit que tu ne maitrises pas vraiment la notion de listeners sur les composants swing et je te conseil très fortement a(vant même de continuer) de te remettre à niveau dessus.


------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

OoWORAoO
0
sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011
1 sept. 2010 à 13:15
Oui effectivement!!
chui débutante en java.et j'aimerais bien travailler avec.
Mais au niveau du combo ça marche très bien avec ou sans action listener,
0
sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011
1 sept. 2010 à 13:29
Pourriez vous m'aider juste au niveau ; lorsque je sélectionne l'un des valeurs du combo par exemple jc1 de retourner la même valeur sur un TextField t1.
NB:le ComboBox jc1 est déjà remplit par des valeurs d'un champs d'une table
0
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
1 sept. 2010 à 14:47
Salut,

les notifications sur les sélections d'un JComboBox peuvent se faire avec le rattachement d'un ActionListener su ce dernier.
Regarde bien ce que je fais dans le code d'exemple que je t'ai fourni plus haut... et ESSAYE le.

En le regardant plus attentivement tu peux voir les lignes importantes :

public class Test extends JFrame implements ActionListener {
...

private JComboBox getComboBox() {
if (comboBox = = null) {
...
comboBox.addActionListener(this);
}
return comboBox;
}
...
// Cette méthode est appelée lors d'un clic sur le combobox ou encore d'un appel de la méthode setSelectedIndex/setSelectedItem du combo
[b]public void actionPerformed(final ActionEvent e) {
final Object o = e.getSource();
if (o.equals(getComboBox())) {
fillTextField("" + getComboBox().getSelectedItem());
}
}/b
}



------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

OoWORAoO
0
sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011
1 sept. 2010 à 15:08
[b]
Je vais essayer encore une fois, et Merci Bcp pour ton aide/b
0
sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011
1 sept. 2010 à 15:40
Re Salut:
Pourriez vous m'expliquer plus si vous permettez la méthode fillTextField(String value) et a quoi sert au juste et surtout s'appuyer sur le deuxième cas (Recherche dans la base donnée)
0
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
1 sept. 2010 à 16:28
Salut,

La méthode fillTextField est juste là pour ne pas mettre directement tout le code dans la fonction listener et faciliter son usage en cas d'appel explicite pour renseigner une valeur par défaut, etc...

Concernant le 2' cas tu y fais ce que tu veux.... si je me base sur ton code ci-dessus ça donnerai un truc genre :

private void fillTextField(String value) {
String s = "select libelle from EtatMateriel where RefEtat='" + value + "'";
Statement st=Accueil.con.createStatement();
ResultSet rst=st.executeQuery(s);
                // récupération du résultat et affectation de ce dernier au champ texte
                getT1().setText(le résultat de ta requete);
}




------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

OoWORAoO
0
sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011
1 sept. 2010 à 19:50
[b]Salut:
c'est très très gentil de votre part pour ce coup de pousse ,
effectivement lorsque j'ai suivi tes conseils j'ai eu au moins un affichage dans Mon TextField t1 Telque "com.microsoft.sqlserver.jdbc.SQLServerResultSet@145582

"et il change de valeurs lorsque je change de valeur dans le ComboBox jc1, vous pouvez me dire c'est quoi en fait!! ou même c'est quoi la faute que j avais commis/b
0
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
1 sept. 2010 à 20:26
Salut,

vu le contenu de ton champ texte tu n'affiches que la variable ResultSet et non la valeur pointée par cette dernière ce qui n'est pas correct... je te conseil de lire des tutos sur les différentes manipulations de l'objet ResultSet.





------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

OoWORAoO
0
monadimustafa Messages postés 5 Date d'inscription lundi 1 février 2010 Statut Membre Dernière intervention 17 janvier 2011
2 sept. 2010 à 01:27
if(jcombobox.getSelectedItem()!=null){
jtextField.setText(jcombobox.getSelectedItem().toString());

}
0
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
2 sept. 2010 à 09:38
Salut,

grave hors sujet..... fin bon je dis ça mais je dis rien Oô





------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

OoWORAoO
0
sarabarbarae Messages postés 13 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 20 avril 2011
2 sept. 2010 à 12:09
[^^confus2]
0
sousouaa Messages postés 4 Date d'inscription mercredi 7 mars 2012 Statut Membre Dernière intervention 24 avril 2012
24 avril 2012 à 21:18
:)
0
cs_croire Messages postés 20 Date d'inscription lundi 2 août 2010 Statut Membre Dernière intervention 22 mai 2012
19 mai 2012 à 15:38
bonjour a tous
j'ai un panel et une jframe; le panel contiens des combobox et une jlist ainsi qu'un JtextArea j'ai pu récupérer le contenue de mes table dans les combobox mais pas dans la jlist et le textarea!! en fait aprés je veux que l'item selectionné dans la combobox soit récupérer sur un jlabel de la frame aprés clique sur le bouton "envoyé"
pouvez vus m'aidez
je suis dessous depuis quelques jours j'ai essayé pas mal de méthodes
mais ça donne rien!
j'attend vos réponse
merci
0
cs_croire Messages postés 20 Date d'inscription lundi 2 août 2010 Statut Membre Dernière intervention 22 mai 2012
20 mai 2012 à 21:28
svp j'attend votre aide
0
cs_croire Messages postés 20 Date d'inscription lundi 2 août 2010 Statut Membre Dernière intervention 22 mai 2012
22 mai 2012 à 13:11
bonjour a tous
je vous fournis mon code des deux classes afin de pouvoir m'aider
je veux récupérer l'item selectionné de mon combobox de la class "combo" sur le label recup_item de ma classe "label"
j'ai pu l'afficher sur la console mais pas sur la classe label
voici le code
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * combo.java
 *
 * Created on 21 mai 2012, 22:58:20
 */

/**
 *
 * @author Microbox
 */
/*--------------------------------------------------------------------------------------------------------------*/
public class combo extends JFrame implements ActionListener {
/**
 * 
 */

JLabel recup_item;
    /** Creates new form combo */
    public combo() {
        initComponents();
        
        this.setLocationRelativeTo(null);

    }

    /** 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();
        jComboBox1 = new javax.swing.JComboBox();
        btn_ok = new javax.swing.JButton();
        btn_ok.setText("ok");
 /*--------------------------------------------------------------------------------------------------------------*/         
        btn_ok.addActionListener(new label(this));
 /*--------------------------------------------------------------------------------------------------------------*/ 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "rouge", "vert", "bleu" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  /*--------------------------------------------------------------------------------------------------------------*/      	
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
 /*--------------------------------------------------------------------------------------------------------------*/
        btn_ok.setText("ok");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(89, 89, 89)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btn_ok)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(63, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                .addComponent(btn_ok)
                .addGap(51, 51, 51))
        );

        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.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
//public void itemStateChanged(ItemEvent ie) {
 recup_item.setText(jComboBox1.getSelectedItem().toString());
    //}
    	 
        // TODO add your handling code here:
    }
/*--------------------------------------------------------------------------------------------------------------*/

    private void btn_okActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    	
    	//new label().setVisible(true);
    	
    	
    }
 /*--------------------------------------------------------------------------------------------------------------*/
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new combo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    public javax.swing.JButton btn_ok;
   public javax.swing.JComboBox jComboBox1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration
    
   /*--------------------------------------------------------------------------------------------------------------*/ 
    public JComboBox getjComboBox1(){ 
    	//JLabel recup_item;
    	
    	return jComboBox1;
    	

    	}
    /*--------------------------------------------------------------------------------------------------------------*/
@Override
public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

} 

}


---------------------------LE CODE DE LA CLASS LABEL-----------------------
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;

import javax.swing.JComboBox;
import javax.swing.JLabel;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * label.java
 *
 * Created on 21 mai 2012, 23:02:10
 */

/**
 *
 * @author Microbox
 */
/*--------------------------------------------------------------------------------------------------------------*/
public class label extends javax.swing.JFrame implements ActionListener {

private combo combo1;
  
public label(combo  combo1) {
this.combo1=combo1;
}	
    /** Creates new form label */
    public label() {
    initComponents();
   this.setLocationRelativeTo(null);
   //pour ne pas fermer la fenetre précedente aprés close de label//
   setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
   
    
    }

    /** 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() {
    	//public void actionPerformed1(ActionEvent arg0) {
        jPanel1 = new javax.swing.JPanel();
        couleur = new javax.swing.JLabel();
        recup_item = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        couleur.setText("couleur choisi");

        recup_item.setForeground(new java.awt.Color(255, 51, 0));
        recup_item.setOpaque(true);
        
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(couleur, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(recup_item, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(45, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(64, 64, 64)
                        .addComponent(recup_item, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addComponent(couleur)))
                .addContainerGap(151, 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>
    
    /**
    * @param args the command line arguments
    */
   

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new label().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
   public javax.swing.JLabel couleur;
    private javax.swing.JPanel jPanel1;
    public javax.swing.JLabel recup_item;
    // End of variables declaration

@Override
/*--------------------------------------------------------------------------------------------------------------*/	

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub
//recup_item.setText(combo1.jComboBox1.getSelectedItem().toString());



String jComboBox1=combo1.getjComboBox1().getSelectedItem().toString();
 
// recup_item.setText("jComboBox1");

 System.out.println(jComboBox1);
 new label().setVisible(true);
 		 
 
 
}
/*--------------------------------------------------------------------------------------------------------------*/
}

j'éspére que vous allez m'aidé
merci d'avance
0
Rejoignez-nous