e814. 创建一个可监听选择状态的菜单项

A menu item can receive notification of selection changes by overriding its menuSelectionChanged() method. See also e808 建立菜单栏,菜单,菜单项.

    JMenuItem item = new JMenuItem("Label") {
        // This method is called whenever the selection status of
        // this menu item is changed
        public void menuSelectionChanged(boolean isSelected) {
            // Always forward the event
            super.menuSelectionChanged(isSelected);
    
            if (isSelected) {
                // The menu item is selected
            } else {
                // The menu item is no longer selected
            }
        }
    };

 

Related Examples
posted @ 2018-09-06 08:53  borter  阅读(127)  评论(0编辑  收藏  举报