List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:GeMSE.GS.Analysis.Stats.OneSamplePCAPanel.java
public OneSamplePCAPanel() { initComponents();// w w w .j av a2s. c o m Color.RGBtoHSB(214, 217, 223, bColor); ButtonGroup groupA = new ButtonGroup(); groupA.add(testAreAtColsRB); groupA.add(testAreAtRowsRB); testAreAtColsRB.setSelected(true); _level = DEFAULT_LEVEL; }
From source file:components.MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*from ww w . j a v a 2 s . c om*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:net.sourceforge.doddle_owl.ui.GeneralOntologySelectionPanel.java
public GeneralOntologySelectionPanel(NameSpaceTable nsTable) { nameSpaceTable = nsTable;//from ww w. java 2 s . c o m edrCheckBox = new JCheckBox(Translator.getTerm("GenericEDRCheckBox"), false); edrCheckBox.addActionListener(this); edrtCheckBox = new JCheckBox(Translator.getTerm("TechnicalEDRCheckBox"), false); edrtCheckBox.addActionListener(this); wnCheckBox = new JCheckBox(Translator.getTerm("WordNetCheckBox"), false); wnCheckBox.addActionListener(this); wnVersionSelectionPanel = new JPanel(); wn30RadioButton = new JRadioButton("3.0"); wn30RadioButton.addChangeListener(this); wn31RadioButton = new JRadioButton("3.1"); wn31RadioButton.setSelected(true); wn31RadioButton.addChangeListener(this); ButtonGroup group = new ButtonGroup(); group.add(wn30RadioButton); group.add(wn31RadioButton); wnVersionSelectionPanel.add(wnCheckBox); wnVersionSelectionPanel.add(wn30RadioButton); wnVersionSelectionPanel.add(wn31RadioButton); JPanel borderPanel = new JPanel(); borderPanel.setLayout(new BorderLayout()); borderPanel.add(wnVersionSelectionPanel, BorderLayout.WEST); jpnWnCheckBox = new JCheckBox(Translator.getTerm("JpnWordNetCheckBox"), false); jpnWnCheckBox.addActionListener(this); jwoCheckBox = new JCheckBox(Translator.getTerm("JWOCheckBox"), false); jwoCheckBox.addActionListener(this); JPanel checkPanel = new JPanel(); checkPanel.add(borderPanel); checkPanel.add(jpnWnCheckBox); checkPanel.add(jwoCheckBox); checkPanel.add(edrCheckBox); checkPanel.add(edrtCheckBox); setLayout(new BorderLayout()); add(checkPanel, BorderLayout.WEST); generalOntologyDirLabel = new JLabel(Utils.TEMP_DIR); removeGeneralOntologyDirButton = new JButton(Translator.getTerm("RemoveGeneralOntologyDirectoryButton")); removeGeneralOntologyDirButton.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); buttonPanel.add(generalOntologyDirLabel, BorderLayout.CENTER); buttonPanel.add(removeGeneralOntologyDirButton, BorderLayout.WEST); add(buttonPanel, BorderLayout.SOUTH); }
From source file:projects.upc.exec.HrDiagram.java
/** * Main constructor.//from ww w .j ava 2 s.com */ public HrDiagram() { List<UpcStar> upcStars = UpcUtils.loadUpcCatalogue(); List<UpcStar> hipStars = UpcUtils.getHipparcosSubset(upcStars); List<UpcStar> unmatchedStars = UpcUtils.getUnmatchedSubset(upcStars); upcStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(upcStars); hipStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(hipStars); unmatchedStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(unmatchedStars); logger.info("Loaded " + upcStarCrossMatches.size() + " UpcStars with SSA cross matches"); logger.info("Loaded " + hipStarCrossMatches.size() + " UpcStars with Hipparcos and SSA cross matches"); logger.info("Loaded " + unmatchedStarCrossMatches.size() + " UpcStars with no parallax cross-match, and with SSA cross matches"); starsToPlot = upcStarCrossMatches; useHip = false; method = METHOD.NAIVE; fMax = 1.0; final JCheckBox plotAllCheckBox = new JCheckBox("Plot all UPC stars: ", true); plotAllCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotAllCheckBox.isSelected()) { starsToPlot = upcStarCrossMatches; updateChart(); } } }); final JCheckBox plotHipCheckBox = new JCheckBox("Plot Hipparcos stars only: ", false); plotHipCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotHipCheckBox.isSelected()) { starsToPlot = hipStarCrossMatches; updateChart(); } } }); final JCheckBox plotUnmatchedCheckBox = new JCheckBox("Plot all stars with no external match: ", false); plotUnmatchedCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotUnmatchedCheckBox.isSelected()) { starsToPlot = unmatchedStarCrossMatches; updateChart(); } } }); final ButtonGroup bg = new ButtonGroup(); bg.add(plotHipCheckBox); bg.add(plotAllCheckBox); bg.add(plotUnmatchedCheckBox); JCheckBox useHipCheckBox = new JCheckBox("Use Hipparcos parallaxes when available", useHip); useHipCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { useHip = !useHip; updateChart(); } }); final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(3, 3)); controls.add(plotAllCheckBox); controls.add(plotHipCheckBox); controls.add(plotUnmatchedCheckBox); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(useHipCheckBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); add(controls, BorderLayout.SOUTH); }
From source file:com.anrisoftware.prefdialog.fields.fieldbutton.AbstractFieldButtonField.java
/** * Sets the button group for this radio button. The button is added to the * specified group.// w w w . j av a 2s . co m * * @param group * the {@link ButtonGroup}. * * @throws NullPointerException * if the specified group is {@code null}. */ public void setButtonGroup(ButtonGroup group) { log.checkButtonGroup(this, group); this.buttonGroup = group; group.add(getComponent()); log.buttonGroupSet(this, group); }
From source file:MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;//from ww w . ja v a 2 s .c om JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/1.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:emailplugin.MailCreator.java
/** * Gives the User the opportunity to specify which Desktop he uses (KDE or * Gnome)/*from w w w. j a va2 s. c om*/ * * @param parent * Parent Dialog * @return true if KDE or Gnome has been selected, false if the User wanted to * specify the App */ private boolean showKdeGnomeDialog(Frame parent) { final JDialog dialog = new JDialog(parent, true); dialog.setTitle(mLocalizer.msg("chooseTitle", "Choose")); JPanel panel = (JPanel) dialog.getContentPane(); panel.setLayout(new FormLayout("10dlu, fill:pref:grow", "default, 3dlu, default, 3dlu, default, 3dlu, default, 3dlu:grow, default")); panel.setBorder(Borders.DIALOG_BORDER); CellConstraints cc = new CellConstraints(); panel.add(UiUtilities.createHelpTextArea(mLocalizer.msg("cantConfigure", "Can't configure on your system")), cc.xyw(1, 1, 2)); JRadioButton kdeButton = new JRadioButton(mLocalizer.msg("kde", "I am using KDE")); panel.add(kdeButton, cc.xy(2, 3)); JRadioButton gnomeButton = new JRadioButton(mLocalizer.msg("gnome", "I am using Gnome")); panel.add(gnomeButton, cc.xy(2, 5)); JRadioButton selfButton = new JRadioButton(mLocalizer.msg("self", "I want to configure by myself")); panel.add(selfButton, cc.xy(2, 7)); ButtonGroup group = new ButtonGroup(); group.add(kdeButton); group.add(gnomeButton); group.add(selfButton); selfButton.setSelected(true); JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.add(ok); panel.add(buttonPanel, cc.xy(2, 9)); UiUtilities.registerForClosing(new WindowClosingIf() { public void close() { dialog.setVisible(false); } public JRootPane getRootPane() { return dialog.getRootPane(); } }); dialog.getRootPane().setDefaultButton(ok); dialog.pack(); UiUtilities.centerAndShow(dialog); if (kdeButton.isSelected()) { mSettings.setApplication("kfmclient"); mSettings.setParameter("exec {content}"); } else if (gnomeButton.isSelected()) { mSettings.setApplication("gnome-open"); mSettings.setParameter("{content}"); } else { Plugin.getPluginManager().showSettings(mPlugin); return false; } return true; }
From source file:net.sf.jabref.importer.fetcher.ACMPortalFetcher.java
@Override public JPanel getOptionsPanel() { JPanel pan = new JPanel(); pan.setLayout(new GridLayout(0, 1)); guideButton.setSelected(true);// www . ja va 2s .co m ButtonGroup group = new ButtonGroup(); group.add(acmButton); group.add(guideButton); pan.add(absCheckBox); pan.add(acmButton); pan.add(guideButton); return pan; }
From source file:com.compomics.cell_coord.gui.controller.summary.VisualizeTracksController.java
/** * Initialize main view/*from w w w.j av a 2s. co m*/ */ private void initVisualizeTracksPanel() { // create new view object visualizeTracksPanel = new VisualizeTracksPanel(); // add radiobuttons to a button group ButtonGroup scaleAxesButtonGroup = new ButtonGroup(); scaleAxesButtonGroup.add(visualizeTracksPanel.getDoNotScaleAxesRadioButton()); scaleAxesButtonGroup.add(visualizeTracksPanel.getScaleAxesRadioButton()); // another button group for the shifted/unshifted coordinates ButtonGroup shiftedCoordinatesButtonGroup = new ButtonGroup(); shiftedCoordinatesButtonGroup.add(visualizeTracksPanel.getRawCoordRadioButton()); shiftedCoordinatesButtonGroup.add(visualizeTracksPanel.getRosePlotRadioButton()); /** * Action Listeners. */ // do not scale the axes visualizeTracksPanel.getDoNotScaleAxesRadioButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int nCols = Integer.parseInt((String) visualizeTracksPanel.getnColumnsComboBox().getSelectedItem()); boolean useRawData = visualizeTracksPanel.getRawCoordRadioButton().isSelected(); resetPlotLogic(); generateDataForPlots(useRawData); // use the data to set the charts setChartsWithCollections(nCols); } }); // scale the axes (use a common scale for all the samples) visualizeTracksPanel.getScaleAxesRadioButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean useRawData = visualizeTracksPanel.getRawCoordRadioButton().isSelected(); for (ChartPanel chartPanel : tracksChartPanels) { scaleAxes(chartPanel.getChart(), useRawData); } } }); // plot the raw tracks visualizeTracksPanel.getRawCoordRadioButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int nCols = Integer.parseInt((String) visualizeTracksPanel.getnColumnsComboBox().getSelectedItem()); resetPlotLogic(); generateDataForPlots(true); // use the data to set the charts setChartsWithCollections(nCols); } }); // make the Rose plot: shift coordinates to origin (zero, zero) visualizeTracksPanel.getRosePlotRadioButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int nCols = Integer.parseInt((String) visualizeTracksPanel.getnColumnsComboBox().getSelectedItem()); resetPlotLogic(); generateDataForPlots(false); // use the data to set the charts setChartsWithCollections(nCols); } }); // replot with a different number of columns visualizeTracksPanel.getnColumnsComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int nCols = Integer.parseInt((String) visualizeTracksPanel.getnColumnsComboBox().getSelectedItem()); boolean useRawData = visualizeTracksPanel.getRawCoordRadioButton().isSelected(); resetPlotLogic(); generateDataForPlots(useRawData); // use the data to set the charts setChartsWithCollections(nCols); } }); visualizeTracksPanel.getDoNotScaleAxesRadioButton().setSelected(true); visualizeTracksPanel.getRawCoordRadioButton().setSelected(true); visualizeTracksPanel.getTracksGraphicsParentPanel().revalidate(); visualizeTracksPanel.getTracksGraphicsParentPanel().repaint(); // add view to parent controller loadTracksController.getMainFrame().getVisualizeTracksParentPanel().add(visualizeTracksPanel, gridBagConstraints); }
From source file:MenuTest.java
public MenuFrame() { setTitle("MenuTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); fileMenu.add(new TestAction("New")); // demonstrate accelerators JMenuItem openItem = fileMenu.add(new TestAction("Open")); openItem.setAccelerator(KeyStroke.getKeyStroke("ctrl O")); fileMenu.addSeparator();/*from w ww. ja v a2 s.c o m*/ saveAction = new TestAction("Save"); JMenuItem saveItem = fileMenu.add(saveAction); saveItem.setAccelerator(KeyStroke.getKeyStroke("ctrl S")); saveAsAction = new TestAction("Save As"); fileMenu.add(saveAsAction); fileMenu.addSeparator(); fileMenu.add(new AbstractAction("Exit") { public void actionPerformed(ActionEvent event) { System.exit(0); } }); // demonstrate check box and radio button menus readonlyItem = new JCheckBoxMenuItem("Read-only"); readonlyItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { boolean saveOk = !readonlyItem.isSelected(); saveAction.setEnabled(saveOk); saveAsAction.setEnabled(saveOk); } }); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem insertItem = new JRadioButtonMenuItem("Insert"); insertItem.setSelected(true); JRadioButtonMenuItem overtypeItem = new JRadioButtonMenuItem("Overtype"); group.add(insertItem); group.add(overtypeItem); // demonstrate icons Action cutAction = new TestAction("Cut"); cutAction.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif")); Action copyAction = new TestAction("Copy"); copyAction.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif")); Action pasteAction = new TestAction("Paste"); pasteAction.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif")); JMenu editMenu = new JMenu("Edit"); editMenu.add(cutAction); editMenu.add(copyAction); editMenu.add(pasteAction); // demonstrate nested menus JMenu optionMenu = new JMenu("Options"); optionMenu.add(readonlyItem); optionMenu.addSeparator(); optionMenu.add(insertItem); optionMenu.add(overtypeItem); editMenu.addSeparator(); editMenu.add(optionMenu); // demonstrate mnemonics JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic('H'); JMenuItem indexItem = new JMenuItem("Index"); indexItem.setMnemonic('I'); helpMenu.add(indexItem); // you can also add the mnemonic key to an action Action aboutAction = new TestAction("About"); aboutAction.putValue(Action.MNEMONIC_KEY, new Integer('A')); helpMenu.add(aboutAction); // add all top-level menus to menu bar JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); // demonstrate pop-ups popup = new JPopupMenu(); popup.add(cutAction); popup.add(copyAction); popup.add(pasteAction); JPanel panel = new JPanel(); panel.setComponentPopupMenu(popup); add(panel); // the following line is a workaround for bug 4966109 panel.addMouseListener(new MouseAdapter() { }); }