Remplir Jcombobox dynamique

Fermé
rwissem Messages postés 12 Date d'inscription vendredi 26 mars 2010 Statut Membre Dernière intervention 12 juin 2010 - Modifié par rwissem le 13/06/2010 à 16:02
bonjour,
voici mon code java de remplissage d'un jcombobox mais le probleme est que
rien n'est afficher.


import java.awt.Color;
import java.awt.Container;
import java.sql.DriverManager;
import java.sql.SQLException;

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


public class pp extends JFrame {

public JLabel code;
public JLabel msg;

public JComboBox code1= new JComboBox();

public static void main (String []arg){
JFrame supp= new pp();
supp.setVisible(true);
supp.setResizable(false);

}

String req1 = "select designation_article from article";
{
try{
String pilote = "com.mysql.jdbc.Driver";
Class.forName(pilote);

java.sql.Connection Connect = DriverManager.getConnection("jdbc:mysql://localhost/mabase", "root", "");

java.sql.Statement instruction=Connect.createStatement() ;
System.out.println("connexion réussi");

java.sql.ResultSet retour2= instruction.executeQuery(req1);
while (retour2.next()){

code1.addItem(retour2.getString("designation_article")) ;

}
retour2.close();


}catch (SQLException e) {
e.printStackTrace();}
catch (Exception e) {
e.printStackTrace();
}}
public pp(){

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setTitle("ajouter un article");
setBounds(100,0,760,768);
getContentPane().setBackground(Color.white);


setTitle("supprimer article");
JComboBox code1=new JComboBox();

this.setLayout(null);



Container contenu = getContentPane();
contenu.setLayout(null);


contenu.add(code1);

code1.setBounds(420,300,120,20);

}

}