re jcombobox avec itemStateChanged
Voilà, j'arrive maintenant à avoir une case vide en 1er mais j'ai un autre pb:
quand j'affiche l'item sélectionné, il m'en affiche 2 (case vide puis item vraiment sélectionné).
Voici mon code:
Code:
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
|
liste.setMaximumRowCount(20);
liste.setPreferredSize(new Dimension(300, 50));
liste.setBackground(Color.WHITE);
//liste.getSelectedItem = -1;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:busnessplan");
Statement stmt = con.createStatement();
String sql="select distinct denomination from Clients";
ResultSet rst=stmt.executeQuery(sql);
liste.removeAllItems();
liste.addItem("");
while(rst.next())
{
liste.addItem(rst.getString("denomination"));
}
} catch(Exception se) {
System.out.println("erreur commise est: "+se);
}
setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
add(liste);
liste.addItemListener(this);
}
public void itemStateChanged(ItemEvent evt)
{
Object obj=evt.getSource();
String s=(String)(evt.getItem());
JOptionPane.showConfirmDialog(null,s,"Juste un test",JOptionPane.PLAIN_MESSAGE);
} catch(Exception se) {
System.out.println("erreur commise est: "+se);
}
} |