List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:StrokeTest.java
/** * Makes a radio button to change the cap style. * @param label the button label//from w w w.j av a 2s .co m * @param style the cap style * @param group the radio button group */ private void makeCapButton(String label, final int style, ButtonGroup group) { // select first button in group boolean selected = group.getButtonCount() == 0; JRadioButton button = new JRadioButton(label, selected); buttonPanel.add(button); group.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { canvas.setCap(style); } }); }
From source file:StrokeTest.java
/** * Makes a radio button to change the join style. * @param label the button label/*from w w w . ja v a 2 s.c om*/ * @param style the join style * @param group the radio button group */ private void makeJoinButton(String label, final int style, ButtonGroup group) { // select first button in group boolean selected = group.getButtonCount() == 0; JRadioButton button = new JRadioButton(label, selected); buttonPanel.add(button); group.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { canvas.setJoin(style); } }); }
From source file:StrokeTest.java
/** * Makes a radio button to set solid or dashed lines * @param label the button label/*ww w .j av a2 s.c om*/ * @param style false for solid, true for dashed lines * @param group the radio button group */ private void makeDashButton(String label, final boolean style, ButtonGroup group) { // select first button in group boolean selected = group.getButtonCount() == 0; JRadioButton button = new JRadioButton(label, selected); buttonPanel.add(button); group.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { canvas.setDash(style); } }); }
From source file:com.jdom.util.patterns.mvp.swing.RadioButtonGroupDialog.java
private RadioButtonGroupDialog(Frame frame, Component locationComp, String labelText, String title, Collection<String> data, String initialValue, String longValue) { super(frame, title, true); final JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); final JButton setButton = new JButton("OK"); setButton.setActionCommand("OK"); setButton.addActionListener(this); getRootPane().setDefaultButton(setButton); ButtonGroup radioButtonGroup = new ButtonGroup(); for (String option : data) { JRadioButton button = new JRadioButton(option); if (option.equals(initialValue)) { button.setSelected(true);/*www . j a v a 2s .co m*/ } radioButtonGroup.add(button); panel.add(button); } JScrollPane listScroller = new JScrollPane(panel); listScroller.setPreferredSize(new Dimension(250, 80)); listScroller.setAlignmentX(LEFT_ALIGNMENT); JPanel listPane = new JPanel(); listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); if (!StringUtils.isEmpty(labelText)) { JLabel label = new JLabel(labelText); label.setText(labelText); listPane.add(label); } listPane.add(Box.createRigidArea(new Dimension(0, 5))); listPane.add(listScroller); listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(cancelButton); buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(setButton); Container contentPane = getContentPane(); contentPane.add(listPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.PAGE_END); pack(); setLocationRelativeTo(locationComp); }
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); bGroup.add(showAncestor);//from ww w .j a v a2 s.c o m 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:algorithm.MetsSubmissionInformationPackage.java
private void createConfigurationPanel() { panel = new GUIPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0;/*from w w w . j a va 2s . co m*/ constraints.gridy = 0; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(new JLabel("<html><h2>Add information to mets file</h2></html>"), constraints); constraints.gridy++; panel.add(new JLabel("Add person: "), constraints); constraints.gridx++; ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(truePersonButton); panel.add(truePersonButton, constraints); constraints.gridx++; buttonGroup.add(falsePersonButton); falsePersonButton.setSelected(true); panel.add(falsePersonButton, constraints); constraints.gridy++; constraints.gridx = 0; panel.add(new JLabel("Name:"), constraints); constraints.gridx++; constraints.gridwidth = 2; panel.add(personField, constraints); constraints.gridwidth = 1; constraints.gridx = 0; constraints.gridy++; 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:MessageDigestTest.java
/** * Adds a radio button to select an algorithm. * @param c the container into which to place the button * @param name the algorithm name/*from w w w . ja va 2 s . co m*/ * @param g the button group */ public void addRadioButton(Container c, final String name, ButtonGroup g) { ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { setAlgorithm(name); } }; JRadioButton b = new JRadioButton(name, g.getButtonCount() == 0); c.add(b); g.add(b); b.addActionListener(listener); }
From source file:ScrollDemo.java
public void init() { JRadioButton form[][] = new JRadioButton[12][5]; String counts[] = { "", "0-1", "2-5", "6-10", "11-100", "101+" }; String categories[] = { "Household", "Office", "Extended Family", "Company (US)", "Company (World)", "Team", "Will", "Birthday Card List", "High School", "Country", "Continent", "Planet" }; JPanel p = new JPanel(); p.setSize(600, 400);/*from w w w. j a va 2s .c om*/ p.setLayout(new GridLayout(13, 6, 10, 0)); for (int row = 0; row < 13; row++) { ButtonGroup bg = new ButtonGroup(); for (int col = 0; col < 6; col++) { if (row == 0) { p.add(new JLabel(counts[col])); } else { if (col == 0) { p.add(new JLabel(categories[row - 1])); } else { form[row - 1][col - 1] = new JRadioButton(); bg.add(form[row - 1][col - 1]); p.add(form[row - 1][col - 1]); } } } } scrollpane = new JScrollPane(p); getContentPane().add(scrollpane, BorderLayout.CENTER); }
From source file:net.lmxm.ute.gui.editors.tasks.SubversionExportTaskEditorPanel.java
/** * Gets the revision pane.//from w ww .j a v a 2 s. c o m * * @return the revision pane */ private JPanel getRevisionPane() { if (revisionPane == null) { revisionPane = new JPanel(new MigLayout("gapy 0")); revisionPane.add(getHeadRevisionRadioButton(), "wrap"); revisionPane.add(getNumberedRevisionRadioButton()); revisionPane.add(getRevisionNumberTextField(), "wrap"); revisionPane.add(getDateRevisionRadioButton()); revisionPane.add(getRevisionDateTextField(), "wrap"); final ButtonGroup group = new ButtonGroup(); group.add(getHeadRevisionRadioButton()); group.add(getNumberedRevisionRadioButton()); group.add(getDateRevisionRadioButton()); } return revisionPane; }
From source file:WeatherFrame.java
public WeatherFrame() { initComponents();//from w w w .j a v a 2 s . co m fc = new JFileChooser(); fc.setMultiSelectionEnabled(true); //only can select a single button a time ButtonGroup group = new ButtonGroup(); group.add(AllRadioButton); group.add(YearlyRadioButton); group.add(MonthlyRadioButton); group.add(WeeklyRadioButton); group.add(DailyRadioButton); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Temperature", "Humidity", "Barometric Pressure", "Windspeed", "UVindex", "Raindfall" })); TempSet = new TimeSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart("Temperature", "", "Degree Fahrenheit", TempSet, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); ChartPanel.setLayout(new java.awt.BorderLayout()); ChartPanel CP = new ChartPanel(chart); CP.setPreferredSize(new Dimension(ChartPanel.getWidth(), ChartPanel.getHeight())); ChartPanel.add(CP, BorderLayout.CENTER); DefaultValueDataset dataset = new DefaultValueDataset(20f); ThermometerPlot thermometerplot = new ThermometerPlot(dataset); JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true); jfreechart.setBackgroundPaint(new Color(240, 240, 240)); thermometerplot.setThermometerPaint(Color.lightGray); thermometerplot.setThermometerStroke(new BasicStroke(2.0F)); ChartPanel DP = new ChartPanel(jfreechart); DP.setPreferredSize(new Dimension(TempThermoPanel.getWidth(), TempThermoPanel.getHeight())); TempThermoPanel.setLayout(new java.awt.BorderLayout()); TempThermoPanel.add(DP); TempThermoPanel.validate(); }