static boolean isSelected(JMenuItem item) {
    if (item == null) return false;
    ButtonModel model = item.getModel();
    if (model == null) return false;
    return model.isArmed() || (item instanceof JMenu) && model.isSelected();
  }
static boolean isSelected(JMenuItem item)