List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:MainClass.java
public MainClass() { theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cp = theFrame.getContentPane();//from w w w .j a v a2s .c o m cp.setLayout(new FlowLayout()); ButtonGroup bg = new ButtonGroup(); JRadioButton bJava = new JRadioButton("Java"); bJava.addActionListener(new LNFSetter("javax.swing.plaf.metal.MetalLookAndFeel", bJava)); bg.add(bJava); cp.add(bJava); JRadioButton bMSW = new JRadioButton("MS-Windows"); bMSW.addActionListener(new LNFSetter("com.sun.java.swing.plaf.windows.WindowsLookAndFeel", bMSW)); bg.add(bMSW); cp.add(bMSW); JRadioButton bMotif = new JRadioButton("Motif"); bMotif.addActionListener(new LNFSetter("com.sun.java.swing.plaf.motif.MotifLookAndFeel", bMotif)); bg.add(bMotif); cp.add(bMotif); JRadioButton bMac = new JRadioButton("Sun-MacOS"); bMac.addActionListener(new LNFSetter("com.sun.java.swing.plaf.mac.MacLookAndFeel", bMac)); bg.add(bMac); cp.add(bMac); String defaultLookAndFeel = UIManager.getSystemLookAndFeelClassName(); JRadioButton bDefault = new JRadioButton("Default"); bDefault.addActionListener(new LNFSetter(defaultLookAndFeel, bDefault)); bg.add(bDefault); cp.add(bDefault); (previousButton = bDefault).setSelected(true); theFrame.pack(); theFrame.setVisible(true); }
From source file:Main.java
public Main() { JRadioButton radMarriedYes = new JRadioButton(new AbstractAction("Yes") { @Override//from ww w. j av a 2 s.c o m public void actionPerformed(ActionEvent arg0) { } }); JRadioButton radMarriedNo = new JRadioButton("No?", false); JRadioButton radGolfYes = new JRadioButton("Yes?", false); JRadioButton radGolfNo = new JRadioButton("No?", true); ButtonGroup radioGroup1 = new ButtonGroup(); ButtonGroup radioGroup2 = new ButtonGroup(); setLayout(null); add(radMarriedYes); add(radMarriedNo); add(radGolfYes); add(radGolfNo); radioGroup1.add(radMarriedYes); radioGroup1.add(radMarriedNo); radioGroup2.add(radGolfYes); radioGroup2.add(radGolfNo); radMarriedYes.setBounds(30, 50, 50, 20); radMarriedNo.setBounds(30, 80, 50, 20); radGolfYes.setBounds(150, 50, 50, 20); radGolfNo.setBounds(150, 80, 50, 20); }
From source file:org.uncommons.watchmaker.swing.evolutionmonitor.PopulationFitnessView.java
/** * Creates the GUI controls for toggling graph display options. * @return A component that can be added to the main panel. */// w w w.j av a 2 s . c o m private JComponent createControls(boolean islands) { JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT)); allDataButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { updateDomainAxisRange(); } }); String text = "Last " + SHOW_FIXED_GENERATIONS + (islands ? " Epochs" : " Generations"); JRadioButton recentDataButton = new JRadioButton(text, true); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(allDataButton); buttonGroup.add(recentDataButton); controls.add(allDataButton); controls.add(recentDataButton); final JCheckBox meanCheckBox = new JCheckBox("Show Mean", true); meanCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { if (itemEvent.getStateChange() == ItemEvent.SELECTED) { dataSet.addSeries(meanSeries); } else { dataSet.removeSeries(meanSeries); } } }); controls.add(meanCheckBox); invertCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { rangeAxis.setInverted(invertCheckBox.isSelected()); } }); controls.add(invertCheckBox); return controls; }
From source file:IntroExample.java
public IntroExample() { JMenu fileMenu = new JMenu("File"); JMenu editMenu = new JMenu("Edit"); JMenu otherMenu = new JMenu("Other"); JMenu subMenu = new JMenu("SubMenu"); JMenu subMenu2 = new JMenu("SubMenu2"); // Assemble the File menus with mnemonics ActionListener printListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Menu item [" + event.getActionCommand() + "] was pressed."); }/*w w w . jav a2 s . c o m*/ }; for (int i = 0; i < fileItems.length; i++) { JMenuItem item = new JMenuItem(fileItems[i], fileShortcuts[i]); item.addActionListener(printListener); fileMenu.add(item); } // Assemble the File menus with keyboard accelerators for (int i = 0; i < editItems.length; i++) { JMenuItem item = new JMenuItem(editItems[i]); item.setAccelerator(KeyStroke.getKeyStroke(editShortcuts[i], Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)); item.addActionListener(printListener); editMenu.add(item); } // Insert a separator in the Edit Menu in Position 1 after "Undo" editMenu.insertSeparator(1); // Assemble the submenus of the Other Menu JMenuItem item; subMenu2.add(item = new JMenuItem("Extra 2")); item.addActionListener(printListener); subMenu.add(item = new JMenuItem("Extra 1")); item.addActionListener(printListener); subMenu.add(subMenu2); // Assemble the Other Menu itself otherMenu.add(subMenu); otherMenu.add(item = new JCheckBoxMenuItem("Check Me")); item.addActionListener(printListener); otherMenu.addSeparator(); ButtonGroup buttonGroup = new ButtonGroup(); otherMenu.add(item = new JRadioButtonMenuItem("Radio 1")); item.addActionListener(printListener); buttonGroup.add(item); otherMenu.add(item = new JRadioButtonMenuItem("Radio 2")); item.addActionListener(printListener); buttonGroup.add(item); otherMenu.addSeparator(); otherMenu.add(item = new JMenuItem("Potted Plant", new ImageIcon("image.gif"))); item.addActionListener(printListener); // Finally, add all the menus to the menu bar add(fileMenu); add(editMenu); add(otherMenu); }
From source file:IsEDTExample.java
public IsEDTExample() { JTable table = new JTable(tableModel); table.setRowHeight(100);/*from w w w . ja v a 2 s. co m*/ table.setDefaultRenderer(Object.class, new ColorRenderer()); add(table); add(new JLabel("Thread Color Shade:")); ButtonGroup group = new ButtonGroup(); JRadioButton redOption = new JRadioButton("Red"); group.add(redOption); redOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = RED; } }); JRadioButton blueOption = new JRadioButton("Blue"); group.add(blueOption); blueOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = BLUE; } }); JRadioButton greenOption = new JRadioButton("Green"); group.add(greenOption); greenOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = GREEN; } }); redOption.setSelected(true); this.threadShade = RED; add(redOption); add(greenOption); add(blueOption); add(new JButton(new RandomColorAction())); this.keepRunning = true; this.colorShadeThread = new Thread(new RandomColorShadeRunnable()); this.colorShadeThread.start(); }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.DefItemEditorPanel.java
/** * @param numInUseArg/*from ww w .j a v a 2s . c o m*/ * @param isRow */ protected void createUI(final int numInUseArg, final boolean isRow) { propsPanel = new RowColDefPanel(item, numInUseArg, isRow); autoPropsPanel = createAutoPropertyPanel(numInUseArg, isRow); cardPanel = new JPanel(cardLayout); cardPanel.add("Auto", autoPropsPanel); cardPanel.add("List", propsPanel); ActionListener action = new ActionListener() { public void actionPerformed(ActionEvent e) { isUsingAuto = autoCB.isSelected(); cardLayout.show(cardPanel, isUsingAuto ? "Auto" : "List"); } }; autoCB = new JRadioButton("Auto"); autoCB.addActionListener(action); listCB = new JRadioButton("List"); listCB.addActionListener(action); ButtonGroup group = new ButtonGroup(); group.add(autoCB); group.add(listCB); autoCB.setSelected(true); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,16px,p,f:p:g", "p")); //$NON-NLS-1$ //$NON-NLS-2$ pb.add(listCB, cc.xy(2, 1)); pb.add(autoCB, cc.xy(4, 1)); add(pb.getPanel(), BorderLayout.NORTH); add(cardPanel, BorderLayout.CENTER); cardLayout.show(cardPanel, "List"); listCB.setSelected(true); isUsingAuto = false; }
From source file:org.wsm.database.tools.editor.ui.GraphPane.java
public GraphPane() { GridBagLayout gbl = new GridBagLayout(); this.setLayout(gbl); this.qesi = new QueryExecStatsInfo(); this.qesi.addPropertyChangeListener(this); dcd = new DefaultCategoryDataset(); JFreeChart chart = getChart(CHART_TYPE_BAR_3D); chart.setBackgroundPaint(Color.white); cp = new ChartPanel(chart); cp.setBorder(BorderFactory.createTitledBorder(null, "Graph", TitledBorder.LEADING, TitledBorder.TOP, UIConstants.LABEL_FONT));// www . j av a 2 s . c o m cp.setMouseZoomable(true, true); //cp.setPreferredSize(new Dimension(700, 500)); gbl.setConstraints(cp, SwingUtils.getGridBagConstraints(0, 0, 2, 1)); this.add(cp); JPanel graphTypeSelectionPanel = new JPanel(); viewBarGraph = new JRadioButton("View Bar Graph", true); viewLineGraph = new JRadioButton("View Line Graph", false); viewLineGraph.setEnabled(false); ButtonGroup bg = new ButtonGroup(); bg.add(viewBarGraph); bg.add(viewLineGraph); GridBagLayout graphTypeGBL = new GridBagLayout(); graphTypeSelectionPanel.setLayout(graphTypeGBL); graphTypeGBL.setConstraints(viewBarGraph, SwingUtils.getGridBagConstraints(0, 0)); graphTypeGBL.setConstraints(viewLineGraph, SwingUtils.getGridBagConstraints(1, 0)); graphTypeSelectionPanel.add(viewBarGraph); graphTypeSelectionPanel.add(viewLineGraph); viewBarGraph.addActionListener(this); viewLineGraph.addActionListener(this); graphTypeSelectionPanel.setBorder(BorderFactory.createTitledBorder(null, "Graph Type", TitledBorder.LEADING, TitledBorder.TOP, UIConstants.LABEL_FONT)); gbl.setConstraints(graphTypeSelectionPanel, SwingUtils.getGridBagConstraints(0, 1, 2, 1)); this.add(graphTypeSelectionPanel); //this.setBounds(50, 100, 100, 200); this.setBackground(Color.WHITE); }
From source file:QandE.LunarPhasesRB.java
private void addWidgets() { /*//from www .ja v a 2 s . c om * Create a label for displaying the moon phase images and * put a border around it. */ phaseIconLabel = new JLabel(); phaseIconLabel.setHorizontalAlignment(JLabel.CENTER); phaseIconLabel.setVerticalAlignment(JLabel.CENTER); phaseIconLabel.setVerticalTextPosition(JLabel.CENTER); phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER); phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5))); phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0), phaseIconLabel.getBorder())); //Create radio buttons with lunar phase choices. JRadioButton newButton = new JRadioButton("New"); newButton.setActionCommand("0"); newButton.setSelected(true); JRadioButton waxingCrescentButton = new JRadioButton("Waxing Crescent"); waxingCrescentButton.setActionCommand("1"); JRadioButton firstQuarterButton = new JRadioButton("First Quarter"); firstQuarterButton.setActionCommand("2"); JRadioButton waxingGibbousButton = new JRadioButton("Waxing Gibbous"); waxingGibbousButton.setActionCommand("3"); JRadioButton fullButton = new JRadioButton("Full"); fullButton.setActionCommand("4"); JRadioButton waningGibbousButton = new JRadioButton("Waning Gibbous"); waningGibbousButton.setActionCommand("5"); JRadioButton thirdQuarterButton = new JRadioButton("Third Quarter"); thirdQuarterButton.setActionCommand("6"); JRadioButton waningCrescentButton = new JRadioButton("Waning Crescent"); waningCrescentButton.setActionCommand("7"); // Create a button group and add the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(newButton); group.add(waxingCrescentButton); group.add(firstQuarterButton); group.add(waxingGibbousButton); group.add(fullButton); group.add(waningGibbousButton); group.add(thirdQuarterButton); group.add(waningCrescentButton); // Display the first image. phaseIconLabel.setIcon(new ImageIcon("images/image0.jpg")); phaseIconLabel.setText(""); //Make the radio buttons appear in a center-aligned column. selectPanel.setLayout(new BoxLayout(selectPanel, BoxLayout.PAGE_AXIS)); selectPanel.setAlignmentX(Component.CENTER_ALIGNMENT); //Add a border around the select panel. selectPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Select Phase"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Add a border around the display panel. displayPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Display Phase"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Add image and moon phases radio buttons to select panel. displayPanel.add(phaseIconLabel); selectPanel.add(newButton); selectPanel.add(waxingCrescentButton); selectPanel.add(firstQuarterButton); selectPanel.add(waxingGibbousButton); selectPanel.add(fullButton); selectPanel.add(waningGibbousButton); selectPanel.add(thirdQuarterButton); selectPanel.add(waningCrescentButton); //Listen to events from the radio buttons. newButton.addActionListener(this); waxingCrescentButton.addActionListener(this); firstQuarterButton.addActionListener(this); waxingGibbousButton.addActionListener(this); fullButton.addActionListener(this); waningGibbousButton.addActionListener(this); thirdQuarterButton.addActionListener(this); waningCrescentButton.addActionListener(this); }
From source file:algorithm.OaiOreSubmissionInformationPackage.java
private void createConfigurationPanel() { panel = new GUIPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0;/*from www . j a v a 2 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:SimpleDraw.java
public SimpleDraw() { this.setTitle("Simple DRAW"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // add check box group ButtonGroup cbg = new ButtonGroup(); JRadioButton lineButton = new JRadioButton("Line"); JRadioButton ovalButton = new JRadioButton("Oval"); JRadioButton rectangleButton = new JRadioButton("Rectangle"); cbg.add(lineButton); cbg.add(ovalButton);//w w w . j a v a 2s .com cbg.add(rectangleButton); lineButton.addActionListener(this); ovalButton.addActionListener(this); rectangleButton.addActionListener(this); rectangleButton.setSelected(true); JPanel radioPanel = new JPanel(new FlowLayout()); radioPanel.add(lineButton); radioPanel.add(ovalButton); radioPanel.add(rectangleButton); this.addMouseListener(this); this.setLayout(new BorderLayout()); this.add(radioPanel, BorderLayout.NORTH); }