Java Code Examples for javax.swing.JRadioButtonMenuItem#addActionListener()

The following examples show how to use javax.swing.JRadioButtonMenuItem#addActionListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetalThemeMenu.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 2
Source File: MetalThemeMenu.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 3
Source File: MetalThemeMenu.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 4
Source File: MetalThemeMenu.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 5
Source File: MetalThemeMenu.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 6
Source File: MetalThemeMenu.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 7
Source File: MetalThemeMenu.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 8
Source File: WorkspaceSwitchAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Initializes listeners atc to the given workspace */
void attachWorkspace(
    Workspace workspace, Workspace[] currentDeskRef, Hashtable workspace2Menu, Hashtable menu2Workspace,
    Hashtable workspace2Listener, JMenu menu
) {
    // bugfix #6116 - change from getName() to getDisplayName()
    JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem();
    Mnemonics.setLocalizedText(menuItem, workspace.getDisplayName());
    HelpCtx.setHelpIDString(menuItem, WorkspaceSwitchAction.class.getName());

    ActionListener listener = createActionListener(menuItem, currentDeskRef, menu2Workspace, workspace2Menu);
    menuItem.addActionListener(listener);
    menu2Workspace.put(listener, workspace);
    workspace2Listener.put(workspace, listener);
    workspace2Menu.put(workspace, menuItem);
    workspace.addPropertyChangeListener(createNameListener(menuItem));
    menu.add(menuItem);
}
 
Example 9
Source File: ToolbarPool.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Updates items in popup menu and returns itself.
*/
public JPopupMenu getContextMenu () {
    removeAll ();

    // generate list of available toolbar panels
    ButtonGroup bg = new ButtonGroup ();
    String current = ToolbarPool.getDefault ().getConfiguration ();
    for( String name : ToolbarPool.getDefault().getConfigurationsNow() ) {
        JRadioButtonMenuItem mi = new JRadioButtonMenuItem (name, (name.compareTo (current) == 0));
        mi.addActionListener (this);
        bg.add (mi);
        this.add (mi);
    }

    return this;
}
 
Example 10
Source File: MetalThemeMenu.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 11
Source File: MetalThemeMenu.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 12
Source File: KarmaChildrenList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public JComponent[] getMenuPresenters() {
    removeAll();
    // #238803
    File configDir = KarmaUtils.getKarmaConfigDir(project);
    List<File> configs = KarmaUtils.findKarmaConfigs(configDir);
    if (configs.isEmpty()) {
        configs = KarmaUtils.findJsFiles(configDir);
    }
    configs = FileUtils.sortFiles(configs);
    if (!configs.isEmpty()) {
        String activeConfig = KarmaPreferences.getConfig(project);
        for (final File config : configs) {
            boolean selected = config.getAbsolutePath().equals(activeConfig);
            JRadioButtonMenuItem configItem = new JRadioButtonMenuItem(config.getName(), selected);
            configItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    KarmaPreferences.setConfig(project, config.getAbsolutePath());
                }
            });
            add(configItem);
        }
    } else {
        setEnabled(false);
    }
    return new JComponent[] {this};
}
 
Example 13
Source File: GUIMenuHelper.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
private JRadioButtonMenuItem createJRadioButtonMenuItem(ActionListener actionListener, ButtonGroup buttonGroup, String name, String actionCommand) {
    JRadioButtonMenuItem jRadioButtonMenuItem = new JRadioButtonMenuItem(name);
    jRadioButtonMenuItem.addActionListener(actionListener);
    jRadioButtonMenuItem.setActionCommand(actionCommand);

    buttonGroup.add(jRadioButtonMenuItem);

    return jRadioButtonMenuItem;
}
 
Example 14
Source File: TestCasePopupMenu.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void init() {
    JMenuItem addRowButton = Utils.createMenuItem("Add Row", ""
            + "Ctrl+Plus to add a row at last"
            + "<br>"
            + "Ctrl+I to insert a row before the selected row"
            + "<br>"
            + "Ctrl+R to replicate the row", Keystroke.ADD_ROWP, actionListener);
    add(addRowButton);
    add(Utils.createMenuItem("Delete Rows", "Ctrl+Minus", Keystroke.REMOVE_ROW, actionListener));
    addSeparator();

    add(Utils.createMenuItem("Toggle BreakPoint", "Ctrl+B", Keystroke.BREAKPOINT, actionListener));
    add(Utils.createMenuItem("Toggle Comment", "Ctrl+/", Keystroke.COMMENT, actionListener));

    addSeparator();
    add(Utils.createMenuItem("Cut", "Ctrl+X", Keystroke.CUT, actionListener));
    add(Utils.createMenuItem("Copy", "Ctrl+C", Keystroke.COPY, actionListener));
    add(Utils.createMenuItem("Paste", "Ctrl+V", Keystroke.PASTE, actionListener));
    addSeparator();
    add(Utils.createMenuItem("Create Reusable", actionListener));

    JMenu goToMenu = new JMenu("Go To");
    goToMenu.add(Utils.createMenuItem("Go To Reusable", actionListener));
    goToMenu.add(Utils.createMenuItem("Go To Object", actionListener));
    goToMenu.add(Utils.createMenuItem("Go To TestData", actionListener));
    add(goToMenu);
    add(Utils.createMenuItem("Paramterize", actionListener));
    addSeparator();

    JRadioButtonMenuItem toggleValidation = new JRadioButtonMenuItem("Toggle Validation", true);
    toggleValidation.addActionListener(actionListener);
    add(toggleValidation);
    addSeparator();

    add(saveMenuItem = Utils.createMenuItem("Save", "Ctrl+S", Keystroke.SAVE, actionListener));
    add(Utils.createMenuItem("Reload", "F5", Keystroke.F5, actionListener));
}
 
Example 15
Source File: ChangePackageViewTypeAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JMenuItem createChoice(final JavaProjectSettings.PackageViewType type, String label) {
    JRadioButtonMenuItem item = new JRadioButtonMenuItem();
    Mnemonics.setLocalizedText(item, label);
    item.setSelected(JavaProjectSettings.getPackageViewType() == type);
    item.addActionListener(new ActionListener() {
        @Override public void actionPerformed(ActionEvent e) {
            JavaProjectSettings.setPackageViewType(type);
        }
    });
    return item;
}
 
Example 16
Source File: ContextualMenuHelper.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
public void addPopupMenu(String popupName,final EnumProperty property,final Runnable runnable) {
	Object[] values = property.getValues();
	JMenu myPopup = new JMenu(popupName);
	for(int a = 0; a<values.length; a++) {
		final Object currentValue = values[a];
		final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(currentValue.toString());
		myPopup.add(menuItem);
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				property.setValue(currentValue);
				SwingUtilities.invokeLater(runnable);
			}
		});

		property.addPropertyChangeListener(new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent evt) {
				SwingUtilities.invokeLater(new Runnable() {
					public void run() {
						menuItem.setSelected(currentValue.equals(property.getValue()));
					}
				});
				SwingUtilities.invokeLater(runnable);
			}
		});
		menuItem.setSelected(currentValue.equals(property.getValue()));
	}
	popup.add(myPopup);
}
 
Example 17
Source File: CompositeMenuToggleButton.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Adds the given {@link Action}s to the {@link #popupMenu}.
 *
 * @param actions
 *            the actions which should be added to the menu
 */
public void addActions(Action... actions) {
	for (Action action : actions) {
		JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);

		item.addActionListener(e -> updateSelectionStatus());
		popupMenuGroup.add(item);
		popupMenu.add(item);
	}
}
 
Example 18
Source File: JCEditor.java    From JCEditor with GNU General Public License v2.0 5 votes vote down vote up
/**
* Método que cria os JRadioButtonMenuItem(s)
* @param nome String - nome do menu
* @param ev ActionListener - evento que será executado ao pressionar o menu
* @param bg ButtonGroup - grupo a qual o menu pertence (não é possível ter mais de um selecionado)
* @param mPrincipal - menu ao qual o menu de rádio pertence
*/
private JRadioButtonMenuItem configRadioMenus(String nome, ActionListener ev, ButtonGroup bg, JMenu mPrincipal) {
	JRadioButtonMenuItem menu = new JRadioButtonMenuItem(nome);
	menu.addActionListener(ev);
	menu.setFont(roboto);
	bg.add(menu);

	mPrincipal.add(menu);
	return menu;
}
 
Example 19
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the tools menu.
 *
 * @return the j menu
 */
private JMenu createToolsMenu() {
  JMenu toolsMenu = new JMenu("Tools");
  toolsMenu.setMnemonic(KeyEvent.VK_T);
  this.tsViewerItem = new JMenuItem("View Typesystem", KeyEvent.VK_T);
  this.tsViewerItem.addActionListener(new ShowTypesystemHandler(this));
  this.tsViewerItem.setEnabled(false);
  toolsMenu.add(this.tsViewerItem);
  this.allAnnotationViewerItem = new JMenuItem("Show Selected Annotations", KeyEvent.VK_A);
  this.allAnnotationViewerItem.addActionListener(new ShowAnnotatedTextHandler(this));
  toolsMenu.add(this.allAnnotationViewerItem);
  this.allAnnotationViewerItem.setEnabled(false);
  this.acdItem = new JMenuItem("Customize Annotation Display", KeyEvent.VK_C);
  toolsMenu.add(this.acdItem);
  this.acdItem.setEnabled(false);
  this.acdItem.addActionListener(new ShowAnnotationCustomizerHandler(this));

  JMenu logConfig = new JMenu("Set Log Level");
  ButtonGroup levelGroup = new ButtonGroup();

  // get current log level setting
  String curLogLevel = LogManager.getLogManager().getProperty(".level");

  // create log config menu with available log levels
  Iterator<Level> levelIt = MainFrame.logLevels.iterator();
  while (levelIt.hasNext()) {
    Level level = levelIt.next();
    JRadioButtonMenuItem item = new JRadioButtonMenuItem(level.toString());
    // select current log level
    if (level.toString().equals(curLogLevel)) {
      item.setSelected(true);
    }
    item.addActionListener(new SetLogConfigHandler());
    levelGroup.add(item);
    logConfig.add(item);
  }
  toolsMenu.add(logConfig);

  JMenuItem logViewer = new JMenuItem("View Log File", KeyEvent.VK_L);
  logViewer.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent event) {
      LogFileViewer viewer = new LogFileViewer("Log file: "
          + MainFrame.this.logFile.getAbsolutePath());
      viewer.addWindowListener(new CloseLogViewHandler(MainFrame.this));
      Dimension dim = getDimension(logViewSizePref);
      if (dim == null) {
        dim = logFileDimensionDefault;
      }
      viewer.init(MainFrame.this.logFile, dim);
    }
  });
  toolsMenu.add(logViewer);

  return toolsMenu;
}
 
Example 20
Source File: AssociationScopeFilterMenu.java    From ontopia with Apache License 2.0 4 votes vote down vote up
/**
 * Configure/reconfigure this menu.
 * @param currentTopicMap The topicmap holding the associations (and their
 *     scopes) to be used in this menu.
 * @param parentListener Allows the caller to act upon actions.
 * @param controller manages the interaction between the gui, model and 
 *     configuration manager
 */
public void configure(TopicMapIF currentTopicMap, ActionListener parentListener,
    VizController controller) {
  if (currentTopicMap == null)
    return;

  ScopeIndexIF scopeix = (ScopeIndexIF) currentTopicMap.getIndex(
          "net.ontopia.topicmaps.core.index.ScopeIndexIF");
  
  // Remove all menu items from this menu.
  removeAll();

  // Add radio-button menu part for "Show All", "Loose Filter" 
  // and "Strict Filter"
  int SHOW_ALL = VizTopicMapConfigurationManager.SHOW_ALL_ASSOCIATION_SCOPES;
  int LOOSE = VizTopicMapConfigurationManager.LOOSE_ASSOCIATION_SCOPES;
  int STRICT = VizTopicMapConfigurationManager.STRICT_ASSOCIATION_SCOPES;
  
  // Create radio buttons for the different ways of filtering.
  
  // Determine which radio button is selected
  int selectedStrictness = controller.getAssociationScopeFilterStrictness();

  String showAll = Messages.getString("Viz.ShowAll");
  String looseFilter = Messages.getString("Viz.LooseFilter");
  String strictFilter = Messages.getString("Viz.StrictFilter");
  
  strictnessMap = new JRadioButtonMenuItem[4];

  // Create radio buttons
  JRadioButtonMenuItem radio1 = new JRadioButtonMenuItem(showAll,
      SHOW_ALL == selectedStrictness);
  JRadioButtonMenuItem radio2 = new JRadioButtonMenuItem(looseFilter,
      LOOSE == selectedStrictness);
  JRadioButtonMenuItem radio3 = new JRadioButtonMenuItem(strictFilter,
      STRICT == selectedStrictness);

  strictnessMap[SHOW_ALL] = radio1;
  strictnessMap[LOOSE] = radio2;
  strictnessMap[STRICT] = radio3;
  
  // Add radio buttons to this menu.
  add(radio1);
  add(radio2);
  add(radio3);

  // Add ActionListeners to the radiobuttons.
  radio1.addActionListener(new StrictnessActionListener(controller, SHOW_ALL,
      parentListener));
  radio2.addActionListener(new StrictnessActionListener(controller, LOOSE,
      parentListener));
  radio3.addActionListener(new StrictnessActionListener(controller, STRICT,
      parentListener));

  // Make a group of radiobuttons to make them all exclusive to each other.
  radioButtons = new ButtonGroup();
  radioButtons.add(radio1);
  radioButtons.add(radio2);
  radioButtons.add(radio3);

  // Add a separating line to this menu.
  addSeparator();
  
  // Create checkboxes for each association scope to determine whether it
  // should be used for filtering.
  
  // Get all topics that are used to scope associations and sort them.
  scopes = new ArrayList(scopeix.getAssociationThemes());
  Collections.sort(scopes, new TopicComparator());
  
  // For each association scoping topic...
  checkBoxes = new ArrayList(scopes.size());
  for (Iterator iter = scopes.iterator(); iter.hasNext();) {
    TopicIF scope = (TopicIF)iter.next();
    
    // Add checkbox for this scope with appropriate name to the menu.
    String name = TopicStringifiers.getDefaultStringifier().toString(scope);
    boolean checked = controller.isInAssociationScopeFilter(scope);
    JCheckBoxMenuItem mItem = new JCheckBoxMenuItem(name, checked);
    add(mItem);
    checkBoxes.add(mItem);
    
    // Set the checkbox to always be enabled.
    boolean enabled = true;
    mItem.addActionListener(new ScopeFilterActionListener(scope, controller, 
        parentListener));
    mItem.setEnabled(enabled);
  }
}