本文介绍了在下拉菜单中导航时如何关闭组合框的自动选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题几乎完全说明了我的问题.

the Title states my problem almost completely.

我有一些从JComboBox派生的组合框类,此外,我们还使用了JGoodies的PlasticUI.我的问题是,当我浏览下拉菜单中的可用项目时这些项目将被自动选择.这仅在使用导航键时发生,用鼠标悬停在对象上很好.在我的情况下,这很糟糕,因为它以某种方式激起了要加载的对象中的延迟加载数据,并极大地降低了组合框的速度.

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 popupthose 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.

如何关闭此行为?

我尝试调试,但是找不到合适的位置来设置断点,因为在后台发生了太多的魔术:/

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

请帮助:)

推荐答案

您可以使用ActionEvent.getModifiers()函数检查是否用键盘或鼠标触发了ItemChangeEvent.

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");
        }
    }
});

这篇关于在下拉菜单中导航时如何关闭组合框的自动选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:26