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
原文地址:https://www.cnblogs.com/borter/p/9596168.html