How to turn off auto selection in combobox while navigating in dropdown?

天涯浪子 提交于 2019-12-14 03:18:46

问题


the Title states my problem almost completely.

I have some combo box classes which derive from JComboBox, additionally we use the PlasticUI from JGoodies. My Problem is that when I navigate through the available items in the drop down popup those items are automatically being selected. This only happens when I use the navigation keys, hovering with the mouse over the objects is fine. In my case this is pretty bad because it somehow provokes the lazy-loaded data in the object to be loaded and slow the combo box down immensely.

How can I turn this behavior off?

I tried debugging, but I cannot find a place to set a breakpoint properly, too much magic happening in the background :/

Plzz help :)


回答1:


You can use the function ActionEvent.getModifiers() to check if the ItemChangeEvent got fired with the keyboard or the mouse.

JCheckBox box = new JCheckBox();
box.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(final ActionEvent e) {
        if (e.getModifiers() == 0) {
            System.out.println("keyboard");
        } else {
            System.out.println("mouse");
        }
    }
});


来源:https://stackoverflow.com/questions/21260842/how-to-turn-off-auto-selection-in-combobox-while-navigating-in-dropdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!