Listening for Changes to the Currently Selected Menu or Menu Item : MenuSelectionManager « Swing « Java Tutorial






import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class Main {
  public static void main(String[] argv) throws Exception {
    MenuSelectionManager.defaultManager().addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent evt) {
            MenuSelectionManager msm = (MenuSelectionManager) evt.getSource();
            MenuElement[] path = msm.getSelectedPath();
            if (path.length == 0) {
            }
          }
        });
  }
}








14.28.MenuSelectionManager
14.28.1.Using MenuSelectionManager to determine the current selection path.Using MenuSelectionManager to determine the current selection path.
14.28.2.Getting the Currently Selected Menu or Menu Item
14.28.3.Create a change listener and register with the menu selection manager
14.28.4.Listening for Changes to the Currently Selected Menu or Menu Item