List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:org.yccheok.jstock.gui.MainFrame.java
private void jMenu9MenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_jMenu9MenuSelected this.jMenu9.removeAll(); final java.util.List<String> watchlistNames = org.yccheok.jstock.watchlist.Utils.getWatchlistNames(); final String currentWatchlistName = this.getJStockOptions().getWatchlistName(); final javax.swing.ButtonGroup buttonGroup = new javax.swing.ButtonGroup(); for (String watchlistName : watchlistNames) { final JMenuItem mi = (JRadioButtonMenuItem) this.jMenu9.add(new JRadioButtonMenuItem(watchlistName)); buttonGroup.add(mi); mi.addActionListener(new ActionListener() { @Override/* ww w . j a v a 2 s . c om*/ public void actionPerformed(ActionEvent e) { final String s = ((JRadioButtonMenuItem) e.getSource()).getText(); if (false == s.equals(currentWatchlistName)) { MainFrame.this.selectActiveWatchlist(s); } } }); mi.setSelected(watchlistName.equals(currentWatchlistName)); } this.jMenu9.addSeparator(); final JMenuItem mi = new JMenuItem(GUIBundle.getString("MainFrame_MultipleWatchlist..."), this.getImageIcon("/images/16x16/stock_timezone.png")); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { multipleWatchlists(); } }); this.jMenu9.add(mi); }
From source file:org.zaproxy.zap.view.MessagePanelsPositionController.java
public MessagePanelsPositionController(HttpPanelRequest requestPanel, HttpPanelResponse responsePanel, MainFrame mainFrame, WorkbenchPanel workbenchPanel) { this.requestPanel = requestPanel; this.responsePanel = responsePanel; this.workbenchPanel = workbenchPanel; this.tabbedWork = workbenchPanel.getTabbedWork(); this.currentPosition = MessagePanelsPosition.TABS_SIDE_BY_SIDE; tabsButtonView = new JToggleButton(new ChangeMessagePanelsPositionAction( MessagePanelsPositionController.class.getResource("/resource/icon/layout_tabbed.png"), MessagePanelsPosition.TABS_SIDE_BY_SIDE)); tabsButtonView.setToolTipText(TABS_VIEW_TOOL_TIP); aboveButtonView = new JToggleButton(new ChangeMessagePanelsPositionAction( MessagePanelsPositionController.class.getResource("/resource/icon/layout_vertical_split.png"), MessagePanelsPosition.PANEL_ABOVE)); aboveButtonView.setToolTipText(ABOVE_VIEW_TOOL_TIP); sideBySideButtonView = new JToggleButton(new ChangeMessagePanelsPositionAction( MessagePanelsPositionController.class.getResource("/resource/icon/layout_horizontal_split.png"), MessagePanelsPosition.PANELS_SIDE_BY_SIDE)); sideBySideButtonView.setToolTipText(SIDE_BY_SIDE_VIEW_TOOL_TIP); ButtonGroup messageTabsPositionButtonGroup = new ButtonGroup(); messageTabsPositionButtonGroup.add(tabsButtonView); messageTabsPositionButtonGroup.add(aboveButtonView); messageTabsPositionButtonGroup.add(sideBySideButtonView); tabsButtonView.setSelected(true);/*from w w w . ja va 2 s . c o m*/ MainToolbarPanel toolbar = mainFrame.getMainToolbarPanel(); toolbar.addButton(tabsButtonView); toolbar.addButton(aboveButtonView); toolbar.addButton(sideBySideButtonView); toolbar.addSeparator(); splitTabbedPanel = new TabbedPanel(); splitTabbedPanel.setAlternativeParent(mainFrame.getPaneDisplay()); splitTabbedPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); }
From source file:org.zeromeaner.gui.reskin.StandaloneFrame.java
private static void add(JToolBar toolbar, ButtonGroup g, AbstractButton b) { b.setFocusable(false);//from w ww .j a v a 2s.c om b.setBorder(null); b.setHorizontalAlignment(SwingConstants.LEFT); toolbar.add(b); if (g != null) g.add(b); }
From source file:pcgen.gui2.dialog.OptionsPathDialog.java
private void addRadioButton(String text, String command, ButtonGroup group, ActionListener listener, GridBagConstraints gbc) { boolean selected = command.equals(selectedDir); if (selected) { text += " (default)"; //for i18n this will need to be handled differently }//from ww w. j a v a 2 s .c o m AbstractButton rButton = new JRadioButton(text); rButton.setActionCommand(command); rButton.setSelected(selected); rButton.addActionListener(listener); group.add(rButton); getContentPane().add(rButton, gbc); }
From source file:pcgen.gui2.prefs.LookAndFeelPanel.java
/** * Instantiates a new look and feel panel. *//*from ww w. j a v a 2s .c o m*/ public LookAndFeelPanel(Dialog parent) { JLabel label; ButtonGroup exclusiveGroup; Border etched = null; TitledBorder title1 = BorderFactory.createTitledBorder(etched, IN_LOOK_AND_FEEL); title1.setTitleJustification(TitledBorder.LEFT); this.setBorder(title1); GridBagLayout gridbag = new GridBagLayout(); this.setLayout(gridbag); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(2, 2, 2, 2); exclusiveGroup = new ButtonGroup(); Action[] actions = LookAndFeelManager.getActions(); laf = new JRadioButton[actions.length - 1]; for (int i = 0; i < laf.length; ++i) { laf[i] = new JRadioButton(actions[i]); int whichChar = (laf[i].getText().charAt(0) == 'C') ? 1 : 0; laf[i].setMnemonic(laf[i].getText().charAt(whichChar)); Utility.buildConstraints(c, 0, i, 3, 1, 0, 0); gridbag.setConstraints(laf[i], c); this.add(laf[i]); exclusiveGroup.add(laf[i]); } skinnedLookFeel.addActionListener(actions[actions.length - 1]); skinnedLookFeel.setText(IN_SKINNED_LAF + ": "); skinnedLookFeel.setToolTipText(LanguageBundle.getString("in_Prefs_skinnedLAFTooltip")); skinnedLookFeel.setMnemonic(LanguageBundle.getMnemonic("in_mn_Prefs_skinnedLAF")); Utility.buildConstraints(c, 0, laf.length, 3, 1, 0, 0); gridbag.setConstraints(skinnedLookFeel, c); this.add(skinnedLookFeel); exclusiveGroup.add(skinnedLookFeel); Utility.buildConstraints(c, 3, laf.length, 1, 1, 1, 0); themepackLabel = new JTextField(LookAndFeelManager.getCurrentThemePack()); themepackLabel.setEditable(false); gridbag.setConstraints(themepackLabel, c); this.add(themepackLabel); Utility.buildConstraints(c, 4, laf.length, 1, 1, 0, 0); themepack = new JButton(IN_CHOOSE); themepack.setToolTipText(LanguageBundle.getString("in_Prefs_chooseSkinTooltip")); gridbag.setConstraints(themepack, c); this.add(themepack); themepack.addActionListener(prefsButtonHandler); Utility.buildConstraints(c, 0, laf.length + 1, 5, 1, 0, 0); label = new JLabel(""); gridbag.setConstraints(label, c); this.add(label); Utility.buildConstraints(c, 0, laf.length + 2, 5, 1, 0, 0); label = new JLabel(LanguageBundle.getString("in_Prefs_restartInfo")); gridbag.setConstraints(label, c); this.add(label); Utility.buildConstraints(c, 0, 20, 5, 1, 1, 1); c.fill = GridBagConstraints.BOTH; label = new JLabel(" "); gridbag.setConstraints(label, c); this.add(label); }
From source file:phex.gui.dialogs.ExportDialog.java
private void initComponents() { closeEventHandler = new CloseEventHandler(); addWindowListener(closeEventHandler); DefaultComboBoxModel model = new DefaultComboBoxModel(); model.insertElementAt(Localizer.getString("ExportDialog_DefaultHTMLExport"), DEFAULT_HTML_INDEX); model.insertElementAt(Localizer.getString("ExportDialog_MagmaYAMLExport"), DEFAULT_MAGMA_YAML_INDEX); model.insertElementAt(Localizer.getString("ExportDialog_MetalinkXMLExport"), DEFAULT_METALINK_XML_INDEX); model.insertElementAt(Localizer.getString("ExportDialog_RSSXMLExport"), DEFAULT_RSS_XML_INDEX); standardExport = new JRadioButton(Localizer.getString("ExportDialog_StandardExportFormat")); standardExport.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { replaceFileExtForStandardExport(); }//from w w w . j ava2 s . com }); customExport = new JRadioButton(Localizer.getString("ExportDialog_CustomExportFormat")); customExport.setToolTipText(Localizer.getString("ExportDialog_TTTCustomExportFormat")); ButtonGroup exportFormatGroup = new ButtonGroup(); exportFormatGroup.add(standardExport); exportFormatGroup.add(customExport); standardExport.setSelected(true); standardExportFormatCB = new JComboBox(model); standardExportFormatCB.addActionListener(new ExportTypeListener()); customExportFormatTF = new JTextField(40); customExportFormatTF.setToolTipText(Localizer.getString("ExportDialog_TTTCustomExportFormat")); customExportFormatTF.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { customExport.setSelected(true); } public void keyReleased(KeyEvent e) { customExport.setSelected(true); } public void keyTyped(KeyEvent e) { customExport.setSelected(true); } }); browseCustomFormat = new JButton(Localizer.getString("ExportDialog_Browse")); browseCustomFormat.addActionListener(new BrowseCustomFileBtnListener()); exportAllFiles = new JRadioButton(Localizer.getString("ExportDialog_ExportAllFiles")); // text will be set on initContent() exportSelectedFiles = new JRadioButton(); ButtonGroup exportSourceGroup = new ButtonGroup(); exportSourceGroup.add(exportAllFiles); exportSourceGroup.add(exportSelectedFiles); outputFileTF = new JTextField(40); File defOutFile = new File(SystemUtils.USER_HOME, "shared_files.html"); outputFileTF.setText(defOutFile.getAbsolutePath()); browseOutFile = new JButton(Localizer.getString("ExportDialog_Browse")); browseOutFile.addActionListener(new BrowseOutFileBtnListener()); magnetInclXs = new JCheckBox(Localizer.getString("ExportDialog_MagnetIncludeXS")); magnetInclXs.setToolTipText(Localizer.getString("ExportDialog_TTTMagnetIncludeXS")); magnetInclFreebase = new JCheckBox(Localizer.getString("ExportDialog_MagnetIncludeFreebase")); magnetInclFreebase.setToolTipText(Localizer.getString("ExportDialog_TTTMagnetIncludeFreebase")); // delay setting initial index to ensure all components are available standardExportFormatCB.setSelectedIndex(0); okBtn = new JButton(Localizer.getString("OK")); okBtn.addActionListener(new OkBtnListener()); cancelBtn = new JButton(Localizer.getString("Cancel")); cancelBtn.addActionListener(closeEventHandler); }
From source file:pl.otros.logview.gui.LogViewMainFrame.java
private void initExperimental() { JMenu menu = new JMenu("Experimental"); menu.add(new JLabel("Experimental features, can have bugs", Icons.LEVEL_WARNING, SwingConstants.LEADING)); menu.add(new JSeparator()); boolean storeOnDisk = StringUtils.equalsIgnoreCase(System.getProperty("cacheEvents"), "true"); JRadioButtonMenuItem radioButtonMemory = new JRadioButtonMenuItem("Memory - faster, more memory required", !storeOnDisk);/* ww w .j a va2 s. c o m*/ radioButtonMemory.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.setProperty("cacheEvents", Boolean.FALSE.toString()); } }); JRadioButtonMenuItem radioButtonDisk = new JRadioButtonMenuItem( "Disk with caching - slower, less memory required", storeOnDisk); radioButtonDisk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.setProperty("cacheEvents", Boolean.TRUE.toString()); } }); final ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(radioButtonDisk); buttonGroup.add(radioButtonMemory); menu.add(new JSeparator(JSeparator.VERTICAL)); menu.add(new JLabel("Keep parsed log events store:")); menu.add(radioButtonMemory); menu.add(radioButtonDisk); final JCheckBox soapFormatterRemoveMultirefsCbx = new JCheckBox(); soapFormatterRemoveMultirefsCbx .setSelected(configuration.getBoolean(ConfKeys.FORMATTER_SOAP_REMOVE_MULTIREFS, false)); AbstractAction enableMultiRefRemoveFeature = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { SoapMessageFormatter soapMessageFormatter = (SoapMessageFormatter) AllPluginables.getInstance() .getMessageFormatters().getElement(SoapMessageFormatter.class.getName()); soapMessageFormatter.setRemoveMultiRefs(soapFormatterRemoveMultirefsCbx.isSelected()); configuration.setProperty(ConfKeys.FORMATTER_SOAP_REMOVE_MULTIREFS, soapFormatterRemoveMultirefsCbx.isSelected()); } }; enableMultiRefRemoveFeature.putValue(Action.NAME, "Remove mulitRefs from SOAP messages"); soapFormatterRemoveMultirefsCbx.setAction(enableMultiRefRemoveFeature); enableMultiRefRemoveFeature.actionPerformed(null); final JCheckBox soapFormatterRemoveXsiForNilElementsCbx = new JCheckBox(); soapFormatterRemoveXsiForNilElementsCbx .setSelected(configuration.getBoolean(FORMATTER_SOAP_REMOVE_XSI_FOR_NIL, false)); AbstractAction soapFormatterRemoveXsiFromNilAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { SoapMessageFormatter soapMessageFormatter = (SoapMessageFormatter) AllPluginables.getInstance() .getMessageFormatters().getElement(SoapMessageFormatter.class.getName()); soapMessageFormatter .setRemoveXsiForNilElements(soapFormatterRemoveXsiForNilElementsCbx.isSelected()); configuration.setProperty(FORMATTER_SOAP_REMOVE_XSI_FOR_NIL, soapFormatterRemoveXsiForNilElementsCbx.isSelected()); } }; soapFormatterRemoveXsiFromNilAction.putValue(Action.NAME, "Remove xsi for for NIL elements from SOAP messages"); soapFormatterRemoveXsiForNilElementsCbx.setAction(soapFormatterRemoveXsiFromNilAction); soapFormatterRemoveXsiFromNilAction.actionPerformed(null); menu.add(soapFormatterRemoveMultirefsCbx); menu.add(soapFormatterRemoveXsiForNilElementsCbx); getJMenuBar().add(menu); QueryFilter queryFilter = new QueryFilter(); allPluginables.getLogFiltersContainer().addElement(queryFilter); JButton b = new JButton("Throw exception"); b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (System.currentTimeMillis() % 2 == 0) { throw new RuntimeException("Exception swing action!"); } else { new Thread(new Runnable() { @Override public void run() { throw new RuntimeException("Exception from tread!"); } }).start(); } } }); menu.add(b); }
From source file:processing.app.Base.java
public void rebuildBoardsMenu() throws Exception { boardsCustomMenus = new LinkedList<>(); // The first custom menu is the "Board" selection submenu JMenu boardMenu = new JMenu(tr("Board")); boardMenu.putClientProperty("removeOnWindowDeactivation", true); MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1); boardMenu.add(new JMenuItem(new AbstractAction(tr("Boards Manager...")) { public void actionPerformed(ActionEvent actionevent) { String filterText = ""; String dropdownItem = ""; if (actionevent instanceof Event) { filterText = ((Event) actionevent).getPayload().get("filterText").toString(); dropdownItem = ((Event) actionevent).getPayload().get("dropdownItem").toString(); }/*from www . j a v a 2s .c o m*/ try { openBoardsManager(filterText, dropdownItem); } catch (Exception e) { //TODO show error e.printStackTrace(); } } })); boardsCustomMenus.add(boardMenu); // If there are no platforms installed we are done if (BaseNoGui.packages.size() == 0) return; // Separate "Install boards..." command from installed boards boardMenu.add(new JSeparator()); // Generate custom menus for all platforms Set<String> customMenusTitles = new LinkedHashSet<>(); for (TargetPackage targetPackage : BaseNoGui.packages.values()) { for (TargetPlatform targetPlatform : targetPackage.platforms()) { customMenusTitles.addAll(targetPlatform.getCustomMenus().values()); } } for (String customMenuTitle : customMenusTitles) { JMenu customMenu = new JMenu(tr(customMenuTitle)); customMenu.putClientProperty("removeOnWindowDeactivation", true); boardsCustomMenus.add(customMenu); } List<JMenuItem> menuItemsToClickAfterStartup = new LinkedList<>(); ButtonGroup boardsButtonGroup = new ButtonGroup(); Map<String, ButtonGroup> buttonGroupsMap = new HashMap<>(); // Cycle through all packages boolean first = true; for (TargetPackage targetPackage : BaseNoGui.packages.values()) { // For every package cycle through all platform for (TargetPlatform targetPlatform : targetPackage.platforms()) { // Add a separator from the previous platform if (!first) boardMenu.add(new JSeparator()); first = false; // Add a title for each platform String platformLabel = targetPlatform.getPreferences().get("name"); if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) { JMenuItem menuLabel = new JMenuItem(tr(platformLabel)); menuLabel.setEnabled(false); boardMenu.add(menuLabel); } // Cycle through all boards of this platform for (TargetBoard board : targetPlatform.getBoards().values()) { if (board.getPreferences().get("hide") != null) continue; JMenuItem item = createBoardMenusAndCustomMenus(boardsCustomMenus, menuItemsToClickAfterStartup, buttonGroupsMap, board, targetPlatform, targetPackage); boardMenu.add(item); boardsButtonGroup.add(item); } } } if (menuItemsToClickAfterStartup.isEmpty()) { menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardMenu)); } for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) { menuItemToClick.setSelected(true); menuItemToClick.getAction().actionPerformed(new ActionEvent(this, -1, "")); } }
From source file:processing.app.Base.java
public void rebuildProgrammerMenu() { programmerMenus = new LinkedList<>(); ButtonGroup group = new ButtonGroup(); for (TargetPackage targetPackage : BaseNoGui.packages.values()) { for (TargetPlatform targetPlatform : targetPackage.platforms()) { for (String programmer : targetPlatform.getProgrammers().keySet()) { String id = targetPackage.getId() + ":" + programmer; @SuppressWarnings("serial") AbstractAction action = new AbstractAction( targetPlatform.getProgrammer(programmer).get("name")) { public void actionPerformed(ActionEvent actionevent) { PreferencesData.set("programmer", "" + getValue("id")); }//from w w w .java 2 s .c o m }; action.putValue("id", id); JMenuItem item = new JRadioButtonMenuItem(action); if (PreferencesData.get("programmer").equals(id)) { item.setSelected(true); } group.add(item); programmerMenus.add(item); } } } }
From source file:psidev.psi.mi.tab.client.gui.DragAndDropConverter.java
public static void addExpansionMenu(JMenuBar menuBar) { ButtonGroup itemGroup = new ButtonGroup(); // Create a menu JMenu menu = new JMenu("Expansion model"); menuBar.add(menu);// ww w.j a v a2 s . com // Create none item JMenuItem noneItem = new JRadioButtonMenuItem("None"); noneItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { log.debug("No expansion strategy selected."); expansionStrategy = null; } }); itemGroup.add(noneItem); menu.add(noneItem); // Create spoke model item JMenuItem spokeItem = new JRadioButtonMenuItem("Spoke"); spokeItem.setSelected(true); spokeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { log.debug("Sets expansion statefy to Spoke."); expansionStrategy = new SpokeExpansion(); } }); itemGroup.add(spokeItem); menu.add(spokeItem); // Create an exit JMenuItem matrixItem = new JRadioButtonMenuItem("Matrix"); matrixItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { log.debug("Sets expansion statefy to Matrix."); expansionStrategy = new MatrixExpansion(); } }); itemGroup.add(matrixItem); menu.add(matrixItem); }