JComboBox qui ne se refresh pas
Je commence a developer en SWING.
quelqu'un peut-il m'aider a comprendre pourquoi le comboBox ne se rafraichit pas comme il se doit....Il se rafraichit au second EVENT/click dans le comboBox, mais il garde toujours le dernier element 'USA':roll:
voici le 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 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
| package day1;
import java.util.*;
import javax.swing.*;
/**
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class RefreshJTable extends JFrame {
private JPanel jContentPane = null;
private Vector columnName = new Vector();
private Vector columneData = new Vector();
private JComboBox jComboBox = null;
public static void main(String[] args) {
RefreshJTable rt = new RefreshJTable();
}
/**
* This is the default constructor
*/
public RefreshJTable() {
super();
initialize();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
/**
* This method initializes this
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
}
/**
* This method initializes jContentPane
*/
private javax.swing.JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJComboBox(), null);
}
return jContentPane;
}
/**
* This method initializes jComboBox
*/
private JComboBox getJComboBox() {
if(jComboBox == null) {
jComboBox = new JComboBox();
columnName.addElement("1");
columnName.addElement("2");
columnName.addElement("3");
jComboBox = new JComboBox(columnName);
jComboBox.setBounds(83, 14, 181, 26);
jComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()");
columnName.addElement("France");
columnName.addElement("Canada");
columnName.addElement("USA");
jComboBox = new JComboBox(columnName);
repaint();
}
});
}
return jComboBox;
}
} // @jve:visual-info decl-index=0 visual-constraint="15,4" |