防止JMenuItem在单击时关闭JMenu

时间:2014-01-30 06:59:55

标签: java swing look-and-feel jmenu jmenuitem

当我使用多个LAF时,如何执行this之类的操作:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

1 个答案:

答案 0 :(得分:0)

我用这种方式解决了我的问题:

public class MyMenuItem extends JMenuItem {

    public MyMenuItem(String text) {
        super(text);
    }

    @Override
    protected void processMouseEvent(MouseEvent evt) {
        if (evt.getID() == MouseEvent.MOUSE_RELEASED  && contains(evt.getPoint())) {
            doClick();
            setArmed(true);
        } else
            super.processMouseEvent(evt);
    }

}