List of usage examples for javax.swing ButtonGroup ButtonGroup
public ButtonGroup()
ButtonGroup
. From source file:algorithm.OaiOreSubmissionInformationPackage.java
private void createConfigurationPanel() { panel = new GUIPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0;/*from w w w.j a v a2 s.c om*/ constraints.gridy = 0; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(new JLabel("Choose archiving technique:"), constraints); constraints.gridx++; ButtonGroup archivingGroup = new ButtonGroup(); archivingGroup.add(tarButton); archivingGroup.add(zipButton); zipButton.setSelected(true); panel.add(zipButton, constraints); constraints.gridy++; panel.add(tarButton, constraints); constraints.gridx = 0; constraints.gridy++; }
From source file:layout.FlowLayoutDemo.java
public void addComponentsToPane(final Container pane) { final JPanel compsToExperiment = new JPanel(); compsToExperiment.setLayout(experimentLayout); experimentLayout.setAlignment(FlowLayout.TRAILING); JPanel controls = new JPanel(); controls.setLayout(new FlowLayout()); LtoRbutton = new JRadioButton(LtoR); LtoRbutton.setActionCommand(LtoR);// ww w . ja v a 2 s . co m LtoRbutton.setSelected(true); RtoLbutton = new JRadioButton(RtoL); RtoLbutton.setActionCommand(RtoL); //Add buttons to the experiment layout compsToExperiment.add(new JButton("Button 1")); compsToExperiment.add(new JButton("Button 2")); compsToExperiment.add(new JButton("Button 3")); compsToExperiment.add(new JButton("Long-Named Button 4")); compsToExperiment.add(new JButton("5")); //Left to right component orientation is selected by default compsToExperiment.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); //Add controls to set up the component orientation in the experiment layout final ButtonGroup group = new ButtonGroup(); group.add(LtoRbutton); group.add(RtoLbutton); controls.add(LtoRbutton); controls.add(RtoLbutton); controls.add(applyButton); //Process the Apply component orientation button press applyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); //Check the selection if (command.equals("Left to right")) { compsToExperiment.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); } else { compsToExperiment.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); } //update the experiment layout compsToExperiment.validate(); compsToExperiment.repaint(); } }); pane.add(compsToExperiment, BorderLayout.CENTER); pane.add(controls, BorderLayout.SOUTH); ; }
From source file:GenealogyExample.java
public GenealogyExample() { super(new BorderLayout()); //Construct the panel with the toggle buttons. JRadioButton showDescendant = new JRadioButton("Show descendants", true); final JRadioButton showAncestor = new JRadioButton("Show ancestors"); ButtonGroup bGroup = new ButtonGroup(); bGroup.add(showDescendant);/*w w w.j ava 2 s . co m*/ bGroup.add(showAncestor); showDescendant.addActionListener(this); showAncestor.addActionListener(this); showAncestor.setActionCommand(SHOW_ANCESTOR_CMD); JPanel buttonPanel = new JPanel(); buttonPanel.add(showDescendant); buttonPanel.add(showAncestor); //Construct the tree. tree = new GenealogyTree(getGenealogyGraph()); JScrollPane scrollPane = new JScrollPane(tree); scrollPane.setPreferredSize(new Dimension(200, 200)); //Add everything to this panel. add(buttonPanel, BorderLayout.PAGE_START); add(scrollPane, BorderLayout.CENTER); }
From source file:com.floreantpos.bo.ui.explorer.QuickMaintenanceExplorer.java
public QuickMaintenanceExplorer() { super(new MigLayout("inset 0")); int btnSize = PosUIManager.getSize(60); btnCursor = new POSToggleButton(); btnCursor.setIcon(IconFactory.getIcon("/ui_icons/", "cursor_hand.png")); btnEdit = new POSToggleButton("EDIT"); btnCopy = new POSToggleButton("COPY"); btnDelete = new POSToggleButton("DEL"); btni18 = new POSToggleButton("i18n"); ButtonGroup group = new ButtonGroup(); group.add(btnCursor);//from w w w. j ava 2 s . c om group.add(btnCopy); group.add(btnEdit); group.add(btnDelete); group.add(btni18); btnEdit.setSelected(true); add(btnCursor, "w " + btnSize + "!, h " + btnSize + "!"); add(btnEdit, "w " + btnSize + "!, h " + btnSize + "!"); add(btnCopy, "w " + btnSize + "!, h " + btnSize + "!"); add(btnDelete, "w " + btnSize + "!, h " + btnSize + "!"); //add(btni18, "w " + btnSize + "!, h " + btnSize + "!"); }
From source file:SimplelookandfeelExample.java
public SimplelookandfeelExample() { // Create the buttons. JButton button = new JButton("Hello, world"); button.setMnemonic('h'); //for looks only; button does nada metalButton = new JRadioButton(metal); metalButton.setMnemonic('o'); metalButton.setActionCommand(metalClassName); motifButton = new JRadioButton(motif); motifButton.setMnemonic('m'); motifButton.setActionCommand(motifClassName); windowsButton = new JRadioButton(windows); windowsButton.setMnemonic('w'); windowsButton.setActionCommand(windowsClassName); // Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(metalButton);/*from www . j a va 2s. c o m*/ group.add(motifButton); group.add(windowsButton); // Register a listener for the radio buttons. RadioListener myListener = new RadioListener(); metalButton.addActionListener(myListener); motifButton.addActionListener(myListener); windowsButton.addActionListener(myListener); add(button); add(metalButton); add(motifButton); add(windowsButton); }
From source file:components.CrayonPanel.java
protected void buildChooser() { setLayout(new GridLayout(0, 1)); ButtonGroup boxOfCrayons = new ButtonGroup(); Border border = BorderFactory.createEmptyBorder(4, 4, 4, 4); redCrayon = createCrayon("red", border); boxOfCrayons.add(redCrayon);//from w ww . j a va 2 s. c o m add(redCrayon); yellowCrayon = createCrayon("yellow", border); boxOfCrayons.add(yellowCrayon); add(yellowCrayon); greenCrayon = createCrayon("green", border); boxOfCrayons.add(greenCrayon); add(greenCrayon); blueCrayon = createCrayon("blue", border); boxOfCrayons.add(blueCrayon); add(blueCrayon); }
From source file:ShowComponent.java
/** * This static method queries the system to find out what Pluggable * Look-and-Feel (PLAF) implementations are available. Then it creates a * JMenu component that lists each of the implementations by name and allows * the user to select one of them using JRadioButtonMenuItem components. * When the user selects one, the selected menu item traverses the component * hierarchy and tells all components to use the new PLAF. *//*from ww w. j av a 2s . co m*/ public static JMenu createPlafMenu(final JFrame frame) { // Create the menu JMenu plafmenu = new JMenu("Look and Feel"); // Create an object used for radio button mutual exclusion ButtonGroup radiogroup = new ButtonGroup(); // Look up the available look and feels UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels(); // Loop through the plafs, and add a menu item for each one for (int i = 0; i < plafs.length; i++) { String plafName = plafs[i].getName(); final String plafClassName = plafs[i].getClassName(); // Create the menu item JMenuItem item = plafmenu.add(new JRadioButtonMenuItem(plafName)); // Tell the menu item what to do when it is selected item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // Set the new look and feel UIManager.setLookAndFeel(plafClassName); // Tell each component to change its look-and-feel SwingUtilities.updateComponentTreeUI(frame); // Tell the frame to resize itself to the its // children's new desired sizes frame.pack(); } catch (Exception ex) { System.err.println(ex); } } }); // Only allow one menu item to be selected at once radiogroup.add(item); } return plafmenu; }
From source file:VoteDialog.java
private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton voteButton = null;/*from ww w .j a v a 2 s .co m*/ final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("<html>Candidate 1: <font color=red>Sparky the Dog</font></html>"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("<html>Candidate 2: <font color=green>Shady Sadie</font></html>"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("<html>Candidate 3: <font color=blue>R.I.P. McDaniels</font></html>"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton( "<html>Candidate 4: <font color=maroon>Duke the Java<font size=-2><sup>TM</sup></font size> Platform Mascot</font></html>"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } // Select the first button by default. radioButtons[0].setSelected(true); voteButton = new JButton("Vote"); voteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "This candidate is a dog. Invalid vote."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "This candidate is a convicted felon. \nDo you still want to vote for her?", "A Follow-up Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("OK. Keep an eye on your wallet."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no (with customized wording) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No, thanks" }; int n = JOptionPane.showOptionDialog(frame, "This candidate is deceased. \nDo you still want to vote for him?", "A Follow-up Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("I hope you don't expect much from your candidate."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no/cancel (with customized wording) } else if (command == yncCommand) { Object[] options = { "Yes!", "No, I'll pass", "Well, if I must" }; int n = JOptionPane.showOptionDialog(frame, "Duke is a cartoon mascot. \nDo you " + "still want to cast your vote?", "A Follow-up Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Excellent choice."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whatever you say. It's your vote."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to make you vote."); } else { setLabel("It is your civic duty to cast your vote."); } } return; } }); System.out.println("calling createPane"); return createPane(simpleDialogDesc + ":", radioButtons, voteButton); }
From source file:au.org.ala.delta.ui.SearchDialog.java
/** * Create the dialog./*from w ww.j av a2 s . co m*/ */ public SearchDialog(SearchController controller) { super(UIUtils.getParentFrame(controller.getOwningComponent())); hookInternalFrame(controller.getOwningComponent()); _controller = controller; UIUtils.centerDialog(this, controller.getOwningComponent().getParent()); setTitle(controller.getTitle()); setName(_controller.getTitle()); setBounds(100, 100, 366, 229); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); SingleFrameApplication application = (SingleFrameApplication) Application.getInstance(); ResourceMap messages = application.getContext().getResourceMap(); JLabel lblFind = new JLabel(messages.getString("searchDialog.lblFind")); lblFind.setMinimumSize(new Dimension(30, 0)); textField = new JTextField(); textField.setColumns(10); JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(null, messages.getString("searchDialog.groupDirection"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); buttonGroup = new ButtonGroup(); rdbtnForwards = new JRadioButton(messages.getString("searchDialog.directionForwards")); rdbtnForwards.setSelected(true); buttonGroup.add(rdbtnForwards); rdbtnBackwards = new JRadioButton(messages.getString("searchDialog.directionBackwards")); buttonGroup.add(rdbtnBackwards); contentPanel.setLayout(new MigLayout("", "[growprio 0,grow,left][grow][grow]", "[20px][21px,grow][grow]")); contentPanel.add(lblFind, "cell 0 0,alignx left,aligny top"); contentPanel.add(textField, "cell 1 0 2 1,growx,aligny top"); final JPanel panel_1 = new JPanel(); panel_1.setBorder(new TitledBorder(null, messages.getString("searchDialog.optionsPanelTitle"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); contentPanel.add(panel_1, "cell 0 1 2 1,grow"); panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS)); chckbxMatchCase = new JCheckBox(messages.getString("searchDialog.lblMatchCase")); panel_1.add(chckbxMatchCase); chckbxWrapSearch = new JCheckBox(messages.getString("searchDialog.lblWrapSearch")); panel_1.add(chckbxWrapSearch); chckbxWrapSearch.setSelected(true); contentPanel.add(panel, "cell 2 1,grow"); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(rdbtnForwards); panel.add(rdbtnBackwards); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton findButton = new JButton(messages.getString("searchDialog.btnFindNext")); findButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { findNext(); } }); buttonPane.add(findButton); getRootPane().setDefaultButton(findButton); } { JButton cancelButton = new JButton(messages.getString("searchDialog.btnCancel")); buttonPane.add(cancelButton); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); } } }
From source file:components.MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;// www . j a va 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"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); 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); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); 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); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); 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)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); 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; }