Вопрос

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?

Это было полезно?

Решение

ActionListener invokes only when you press Enter key. For first clicking I recommend you to use FocusListener or MouseListener on your JComboBox.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top