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 |