I have a JComboBox
JComboBox tableChoose = new JComboBox();
tableChoose.addItem("Bill");
tableChoose.addItem("Bob");
tableChoose.setSelectedItem("Bill");
and some handling methods
public void addComboActionListener(IComboHandler handler){
tableChoose.addActionListener(handler);
}
public Object getTableChooseSelectedItem(){
return tableChoose.getSelectedItem();
}
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null, fileReaderWindow.getTableChooseSelectedItem() , null, JOptionPane.ERROR_MESSAGE);
}
As you see, I set "Bill" as first selected item. When I run the program, I have to reselect "Bill" in order to fire the event in actionPerfomed
.
Is there a way to fire the event without reselecting the item in JComboBox? Thank you in advance.