Reputation: 3
in my project, i have a empty combobox which i want to populate after clicking on it.
comboCurrent = new JComboBox<String>();
comboCurrent.setBounds(265, 181, 80, 20);
add(comboCurrent);
comboCurrent.setEditable(true);
comboCurrent.setSelectedItem(null);
comboCurrent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO populate here
System.out.println(e);
}
});
but somehow the action listener does not work here. is there a way to listen to the first click on the combobox while it is still empty?
Upvotes: 0
Views: 75
Reputation: 10994
ActionListener
invokes only when you press Enter key. For first clicking I recommend you to use FocusListener
or MouseListener
on your JComboBox
.
Upvotes: 2