문제

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