List of usage examples for javax.swing JRadioButtonMenuItem setActionCommand
public void setActionCommand(String actionCommand)
From source file:RadioButtonSample.java
public static void main(String args[]) { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { AbstractButton aButton = (AbstractButton) actionEvent.getSource(); boolean selected = aButton.getModel().isSelected(); System.out.println(actionEvent.getActionCommand() + " - selected? " + selected); }//from w w w . j a v a 2 s.c o m }; ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { AbstractButton aButton = (AbstractButton) itemEvent.getSource(); int state = itemEvent.getStateChange(); String selected = ((state == ItemEvent.SELECTED) ? "selected" : "not selected"); System.out.println(aButton.getText() + " - selected? " + selected); } }; JFrame frame = new JFrame("Radio Menu Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Menu"); ButtonGroup buttonGroup = new ButtonGroup(); menu.setMnemonic(KeyEvent.VK_M); JRadioButtonMenuItem emptyMenuItem = new JRadioButtonMenuItem(); emptyMenuItem.setActionCommand("Empty"); emptyMenuItem.addActionListener(actionListener); buttonGroup.add(emptyMenuItem); menu.add(emptyMenuItem); JRadioButtonMenuItem oneMenuItem = new JRadioButtonMenuItem("Partridge"); oneMenuItem.addActionListener(actionListener); buttonGroup.add(oneMenuItem); menu.add(oneMenuItem); JRadioButtonMenuItem twoMenuItem = new JRadioButtonMenuItem("Turtle Doves", true); twoMenuItem.addActionListener(actionListener); buttonGroup.add(twoMenuItem); menu.add(twoMenuItem); JRadioButtonMenuItem threeMenuItem = new JRadioButtonMenuItem("French Hens", threeIcon); threeMenuItem.addItemListener(itemListener); buttonGroup.add(threeMenuItem); menu.add(threeMenuItem); JRadioButtonMenuItem fourMenuItem = new JRadioButtonMenuItem("Calling Birds", fourIcon, true); fourMenuItem.addActionListener(actionListener); buttonGroup.add(fourMenuItem); menu.add(fourMenuItem); JRadioButtonMenuItem fiveMenuItem = new JRadioButtonMenuItem(fiveIcon); fiveMenuItem.addActionListener(actionListener); fiveMenuItem.setActionCommand("Rings"); buttonGroup.add(fiveMenuItem); menu.add(fiveMenuItem); JRadioButtonMenuItem sixMenuItem = new JRadioButtonMenuItem(sixIcon, true); sixMenuItem.addActionListener(actionListener); sixMenuItem.setActionCommand("Geese"); buttonGroup.add(sixMenuItem); menu.add(sixMenuItem); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java
/** * Constucts a JMenu named 'name' with a a RadioButton for each * object in 'themeArray'.//from w w w . ja v a2 s . c om * * @param name the visible name for the Menu. * @param themeArray the array of themes to put in the menu. */ public MetalThemeMenu(String name, MetalTheme[] themeArray) { super(name); themeNames = ResourceBundle.getBundle(BASE_NAME, Locale.getDefault()); themes = themeArray; ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem defaultItem = null; for (int i = 0; i < themes.length; i++) { String themeName; try { themeName = themeNames.getString(themes[i].getName().replaceAll("\\s", "")); } catch (MissingResourceException mre) { themeName = themes[i].getName(); Object[] noResourceArgs = { themes[i].getName(), getLocale() }; MessageFormat form = new MessageFormat(themeNames.getString("message.error.noResource")); log.error(form.format(noResourceArgs)); } JRadioButtonMenuItem item = new JRadioButtonMenuItem(themeName); group.add(item); add(item); item.setActionCommand(i + ""); item.addActionListener(this); // Theme name without spaces is the key for looking up localized item text. item.setName(themes[i].getName().replaceAll(" ", "")); if (i == 0) { item.setSelected(true); defaultItem = item; } } //add listener for 'locale' bound property RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this); defaultItem.doClick(); }
From source file:net.sf.firemox.AbstractMainForm.java
/** * Initialize the components of this form. *//*w ww. ja v a2s . c o m*/ protected void initAbstractMenu() { // "TBS" menu tbsMenu = UIHelper.buildMenu("menu_options_tbs"); ButtonGroup group4 = new ButtonGroup(); final MdbListener mdbListener = new MdbListener(this); final File[] mdbs = MToolKit.getFile(IdConst.TBS_DIR) .listFiles((FileFilter) FileFilterUtils.suffixFileFilter("xml")); String defaultTbs = MToolKit.tbsName; for (File mdb : mdbs) { String mdbName = FilenameUtils.getBaseName(mdb.getName()); JRadioButtonMenuItem itemChck = new JRadioButtonMenuItem(); MToolKit.tbsName = mdbName; updateMdbMenu(mdbName, itemChck); itemChck.setActionCommand(mdbName); itemChck.setFont(MToolKit.defaultFont); itemChck.addActionListener(mdbListener); group4.add(itemChck); tbsMenu.add(itemChck); if (mdbName.equals(defaultTbs)) { itemChck.setSelected(true); } } MToolKit.tbsName = defaultTbs; tbsMenu.add(new JSeparator()); // "More TBS" menu item tbsMenu.add(UIHelper.buildMenu("menu_options_tbs_more", mdbListener)); tbsMenu.add(new JSeparator()); final JMenuItem updateMdbMenu = UIHelper.buildMenu("menu_options_tbs_update", mdbListener); updateMdbMenu.setEnabled(false); tbsMenu.add(updateMdbMenu); tbsMenu.add(UIHelper.buildMenu("menu_options_tbs_rebuild", mdbListener)); optionMenu.add(new JSeparator()); optionMenu.add(tbsMenu); }
From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java
private JMenu createViewMenu() { JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic('v'); JMenu lnfMenu = new JMenu("Look and Feel"); lnfMenu.setMnemonic('f'); ButtonGroup lnfGroup = new ButtonGroup(); LookAndFeelInfo lnfs[] = UIManager.getInstalledLookAndFeels(); String lnfCurrentName = null; LookAndFeel lnfCurrent = UIManager.getLookAndFeel(); if (lnfCurrent != null) { lnfCurrentName = lnfCurrent.getClass().getName(); }//from w w w. ja v a 2 s . c o m UISwitcher switcher = new UISwitcher(); for (int i = 0; i < lnfs.length; i++) { JRadioButtonMenuItem lnfItem = new JRadioButtonMenuItem(lnfs[i].getName()); lnfItem.addActionListener(switcher); lnfItem.setActionCommand(lnfs[i].getClassName()); lnfGroup.add(lnfItem); lnfMenu.add(lnfItem); if (lnfs[i].getClassName().equals(lnfCurrentName)) { lnfGroup.setSelected(lnfItem.getModel(), true); } } viewMenu.add(lnfMenu); return viewMenu; }
From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java
private void addTopMenu() { JRadioButtonMenuItem mnuTop5 = new JRadioButtonMenuItem("Top 5"); JRadioButtonMenuItem mnuTop10 = new JRadioButtonMenuItem("Top 10"); mnuTop5.setActionCommand("top.5"); mnuTop5.addActionListener(this); mnuTop5.setSelected(true);/*from w w w . java 2 s . c o m*/ mnuTop10.setActionCommand("top.10"); mnuTop10.addActionListener(this); topGroup.add(mnuTop5); topGroup.add(mnuTop10); JMenu menuTop = new JMenu("Top"); menuTop.add(mnuTop5); menuTop.add(mnuTop10); menu.add(menuTop); }
From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java
private void addOrientationMenu() { JRadioButtonMenuItem mnuHorizontal = new JRadioButtonMenuItem("Horizontal"); JRadioButtonMenuItem mnuVertical = new JRadioButtonMenuItem("Vertical"); mnuHorizontal.setActionCommand("orientation.horizontal"); mnuHorizontal.addActionListener(this); mnuHorizontal.setSelected(true);/*w w w.j a v a 2s. c om*/ mnuVertical.setActionCommand("orientation.vertical"); mnuVertical.addActionListener(this); orientationGroup.add(mnuHorizontal); orientationGroup.add(mnuVertical); JMenu menuOrientation = new JMenu("Orientation"); menuOrientation.add(mnuHorizontal); menuOrientation.add(mnuVertical); menu.add(menuOrientation); }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java
private JMenu getSessionIssuerMenu(ButtonGroup buttonGroup) { JRadioButtonMenuItem mnuSiType = new JRadioButtonMenuItem("Type"); JRadioButtonMenuItem mnuSiArn = new JRadioButtonMenuItem("Arn"); JRadioButtonMenuItem mnuSiPrincipalId = new JRadioButtonMenuItem("Principal Id"); JRadioButtonMenuItem mnuSiAccountId = new JRadioButtonMenuItem("Account Id"); JRadioButtonMenuItem mnuSiUsername = new JRadioButtonMenuItem("Username"); mnuSiType.setActionCommand("UserIdentity.SessionContext.SessionIssuer.Type"); mnuSiType.addActionListener(this); mnuSiPrincipalId.setActionCommand("UserIdentity.SessionContext.SessionIssuer.PrincipalId"); mnuSiPrincipalId.addActionListener(this); mnuSiArn.setActionCommand("UserIdentity.SessionContext.SessionIssuer.Arn"); mnuSiArn.addActionListener(this); mnuSiAccountId.setActionCommand("UserIdentity.SessionContext.SessionIssuer.AccountId"); mnuSiAccountId.addActionListener(this); mnuSiUsername.setActionCommand("UserIdentity.SessionContext.SessionIssuer.UserName"); mnuSiUsername.addActionListener(this); buttonGroup.add(mnuSiType);// w w w . ja va2 s .c o m buttonGroup.add(mnuSiPrincipalId); buttonGroup.add(mnuSiArn); buttonGroup.add(mnuSiAccountId); buttonGroup.add(mnuSiUsername); JMenu siMenu = new JMenu("Session Issuer"); siMenu.add(mnuSiType); siMenu.add(mnuSiPrincipalId); siMenu.add(mnuSiArn); siMenu.add(mnuSiAccountId); siMenu.add(mnuSiUsername); return siMenu; }
From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java
private void addStyleMenu() { JRadioButtonMenuItem mnuPie = new JRadioButtonMenuItem("Pie"); JRadioButtonMenuItem mnuPie3d = new JRadioButtonMenuItem("Pie 3D"); JRadioButtonMenuItem mnuBar = new JRadioButtonMenuItem("Bar"); JRadioButtonMenuItem mnuBar3d = new JRadioButtonMenuItem("Bar 3d"); mnuPie.setActionCommand("style.Pie"); mnuPie.addActionListener(this); mnuPie.setSelected(true);//from w w w . j a v a 2 s . co m mnuPie3d.setActionCommand("style.Pie3d"); mnuPie3d.addActionListener(this); mnuBar.setActionCommand("style.Bar"); mnuBar.addActionListener(this); mnuBar3d.setActionCommand("style.Bar3d"); mnuBar3d.addActionListener(this); styleGroup.add(mnuPie); styleGroup.add(mnuPie3d); styleGroup.add(mnuBar); styleGroup.add(mnuBar3d); JMenu menuStyle = new JMenu("Style"); menuStyle.add(mnuPie); menuStyle.add(mnuPie3d); menuStyle.add(mnuBar); menuStyle.add(mnuBar3d); menu.add(menuStyle); }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java
private JMenu getUserIdentityMenu(ButtonGroup buttonGroup) { JRadioButtonMenuItem mnuUiType = new JRadioButtonMenuItem("Type"); JRadioButtonMenuItem mnuUiPrincipalId = new JRadioButtonMenuItem("Principal Id"); JRadioButtonMenuItem mnuUiArn = new JRadioButtonMenuItem("Arn"); JRadioButtonMenuItem mnuUiAccountId = new JRadioButtonMenuItem("Account Id"); JRadioButtonMenuItem mnuUiAccessKeyId = new JRadioButtonMenuItem("Access Key Id"); JRadioButtonMenuItem mnuUiUsername = new JRadioButtonMenuItem("Username"); JRadioButtonMenuItem mnuUiInvokedBy = new JRadioButtonMenuItem("Invoked By"); mnuUiType.setActionCommand("UserIdentity.Type"); mnuUiType.addActionListener(this); mnuUiPrincipalId.setActionCommand("UserIdentity.PrincipalId"); mnuUiPrincipalId.addActionListener(this); mnuUiArn.setActionCommand("UserIdentity.Arn"); mnuUiArn.addActionListener(this); mnuUiAccountId.setActionCommand("UserIdentity.AccountId"); mnuUiAccountId.addActionListener(this); mnuUiAccessKeyId.setActionCommand("UserIdentity.AccessKeyId"); mnuUiAccessKeyId.addActionListener(this); mnuUiUsername.setActionCommand("UserIdentity.UserName"); mnuUiUsername.addActionListener(this); mnuUiInvokedBy.setActionCommand("UserIdentity.InvokedBy"); mnuUiInvokedBy.addActionListener(this); buttonGroup.add(mnuUiType);// w w w.ja v a 2s .c om buttonGroup.add(mnuUiPrincipalId); buttonGroup.add(mnuUiArn); buttonGroup.add(mnuUiAccountId); buttonGroup.add(mnuUiAccessKeyId); buttonGroup.add(mnuUiUsername); buttonGroup.add(mnuUiInvokedBy); JMenu userIdentityMenu = new JMenu("User Identity"); userIdentityMenu.add(mnuUiType); userIdentityMenu.add(mnuUiPrincipalId); userIdentityMenu.add(mnuUiArn); userIdentityMenu.add(mnuUiAccountId); userIdentityMenu.add(mnuUiAccessKeyId); userIdentityMenu.add(mnuUiUsername); userIdentityMenu.add(mnuUiInvokedBy); userIdentityMenu.add(getSessionContextMenu(buttonGroup)); return userIdentityMenu; }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java
@Override public void addCustomMenu() { JRadioButtonMenuItem mnuEventName = new JRadioButtonMenuItem("Event Name"); JRadioButtonMenuItem mnuAwsRegion = new JRadioButtonMenuItem("AWS Region"); JRadioButtonMenuItem mnuSourceIpAddress = new JRadioButtonMenuItem("Source IP Address"); JRadioButtonMenuItem mnuUserAgent = new JRadioButtonMenuItem("User Agent"); JRadioButtonMenuItem mnuEventSource = new JRadioButtonMenuItem("Event Source"); JRadioButtonMenuItem mnuErrorCode = new JRadioButtonMenuItem("Error Code"); JRadioButtonMenuItem mnuRecipientAccountId = new JRadioButtonMenuItem("Recipient Account Id"); mnuEventName.setActionCommand("EventName"); mnuEventName.addActionListener(this); mnuEventName.setSelected(true);/*from w w w . ja v a 2s. c o m*/ mnuAwsRegion.setActionCommand("AwsRegion"); mnuAwsRegion.addActionListener(this); mnuSourceIpAddress.setActionCommand("SourceIPAddress"); mnuSourceIpAddress.addActionListener(this); mnuUserAgent.setActionCommand("UserAgent"); mnuUserAgent.addActionListener(this); mnuEventSource.setActionCommand("EventSource"); mnuEventSource.addActionListener(this); mnuErrorCode.setActionCommand("ErrorCode"); mnuErrorCode.addActionListener(this); mnuRecipientAccountId.setActionCommand("RecipientAccountId"); mnuRecipientAccountId.addActionListener(this); customGroup.add(mnuEventName); customGroup.add(mnuAwsRegion); customGroup.add(mnuSourceIpAddress); customGroup.add(mnuUserAgent); customGroup.add(mnuEventSource); customGroup.add(mnuErrorCode); customGroup.add(mnuRecipientAccountId); JMenu sourceMenu = new JMenu("Event"); sourceMenu.add(mnuEventName); sourceMenu.add(mnuAwsRegion); sourceMenu.add(mnuSourceIpAddress); sourceMenu.add(mnuUserAgent); sourceMenu.add(mnuEventSource); sourceMenu.add(mnuErrorCode); sourceMenu.add(mnuRecipientAccountId); sourceMenu.add(getUserIdentityMenu(customGroup)); menu.add(sourceMenu); }