List of usage examples for javax.swing JRadioButton JRadioButton
public JRadioButton(String text)
From source file:UndoableToggleApp.java
public UndoableToggleApp() { // Create some toggle buttons (and subclasses) JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); // Add our listener to each toggle button SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//from w w w .j a v a2 s . c o m cb.addActionListener(sl); radio.addActionListener(sl); // Layout the buttons Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); // Create undo and redo buttons (initially disabled) undoButton = new JButton("Undo"); redoButton = new JButton("Redo"); undoButton.setEnabled(false); redoButton.setEnabled(false); // Add a listener to the undo button. It attempts to call undo() on the // current edit, then enables/disables the undo/redo buttons as // appropriate. undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Add a redo listener: just like the undo listener, but for redo this // time. redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Layout the undo/redo buttons Box undoRedoBox = new Box(BoxLayout.X_AXIS); undoRedoBox.add(Box.createGlue()); undoRedoBox.add(undoButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(redoButton); undoRedoBox.add(Box.createGlue()); // Layout the main frame Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:IsEDTExample.java
public IsEDTExample() { JTable table = new JTable(tableModel); table.setRowHeight(100);//from w w w .j a v a2 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:UndoableToggleApp2.java
public UndoableToggleApp2() { // Create some toggle buttons (and subclasses) JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); // Add our listener to each toggle button SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//ww w .j a va 2s .c o m cb.addActionListener(sl); radio.addActionListener(sl); // Lay out the buttons Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); // Create undo and redo buttons (initially disabled) undoButton = new JButton("Undo"); redoButton = new JButton("Redo"); endButton = new JButton("End"); undoButton.setEnabled(false); redoButton.setEnabled(false); endButton.setEnabled(false); // Add a listener to the undo button. It attempts to call undo() on the // current edit, then enables/disables the undo/redo buttons as // appropriate. undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Add a redo listener: just like the undo listener, but for redo this // time. redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Add an end listener. This listener will call end() on the // CompoundEdit // and update the undo/redo buttons. endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); // Layout the undo/redo/end buttons Box undoRedoEndBox = new Box(BoxLayout.X_AXIS); undoRedoEndBox.add(Box.createGlue()); undoRedoEndBox.add(undoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(redoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(endButton); undoRedoEndBox.add(Box.createGlue()); // Layout the main frame Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoEndBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:Main.java
public Main() { JPanel northPanel = new JPanel(); northPanel.setLayout(new GridLayout(3, 1, 0, 5)); northPanel.add(label);/* w w w . jav a2s. c o m*/ northPanel.add(button); northPanel.add(comboBox); add(northPanel, BorderLayout.NORTH); JPanel southPanel = new JPanel(); ItemHandler handler = new ItemHandler(); southPanel.setLayout(new GridLayout(1, radio.length)); ButtonGroup group = new ButtonGroup(); for (int i = 0; i < radio.length; i++) { radio[i] = new JRadioButton(strings[i]); radio[i].addItemListener(handler); group.add(radio[i]); southPanel.add(radio[i]); } add(southPanel, BorderLayout.SOUTH); setSize(300, 200); setVisible(true); radio[0].setSelected(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:ToggleButtonCheckBoxRadioButton.java
public TogglePanel() { JToggleButton tog = new JToggleButton("Toggle"); ItemListener listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { AbstractButton src = (AbstractButton) (e.getSource()); System.out.println("Toggle: " + src.getText()); }//from www . j ava2 s . c o m }; tog.addItemListener(listener); add(tog); JCheckBox cbox = new JCheckBox("Checkbox"); cbox.addItemListener(listener); add(cbox); ButtonGroup btngroup = new ButtonGroup(); for (int i = 1; i <= 3; i++) { JRadioButton radio = new JRadioButton("Radio " + i); btngroup.add(radio); radio.addItemListener(listener); add(radio); } }
From source file:UndoableToggleApp4.java
public UndoableToggleApp4() { // Create some toggle buttons (and subclasses). tog = new JToggleButton("ToggleButton"); cb = new JCheckBox("CheckBox"); radio = new JRadioButton("RadioButton"); // Add our listener to the buttons. SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//from w w w. j a v a2 s .co m cb.addActionListener(sl); radio.addActionListener(sl); // Lay out the buttons. Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); // Create undo, redo, start, and end buttons. startButton = new JButton("Start"); endButton = new JButton("End"); undoButton = new JButton("Undo"); redoButton = new JButton("Redo"); startButton.setEnabled(true); endButton.setEnabled(false); undoButton.setEnabled(false); redoButton.setEnabled(false); // Add a listener to the start button. It creates a new StateEdit, // passing in this frame as the StateEditable. startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit = new StateEdit(UndoableToggleApp4.this); startButton.setEnabled(false); endButton.setEnabled(true); //undoButton.setEnabled(edit.canUndo()); // // NOTE: We really don't want to be able to undo until end() is // pressed, // but StateEdit does not enforce this for us! undoButton.setEnabled(false); redoButton.setEnabled(edit.canRedo()); } }); // Add a listener to the end button. It will call end() on the // StateEdit. endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); startButton.setEnabled(true); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); // Add a listener to the undo button. It attempts to call undo() on the // current edit, then enables/disables the undo/redo buttons as // appropriate. undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Add a redo listener: just like the undo listener. redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Lay out the state/end and undo/redo buttons. Box undoRedoBox = new Box(BoxLayout.X_AXIS); undoRedoBox.add(Box.createGlue()); undoRedoBox.add(startButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(endButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(undoButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(redoButton); undoRedoBox.add(Box.createGlue()); // Lay out the main frame. Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:de.fhg.iais.asc.ui.i18n.LocalizedUI.java
public static JRadioButton createRadioButton(String key) { key = "Radiobutton." + key; String tooltipText = Messages.getString("Tooltip." + key, ""); JRadioButton radioButton = new JRadioButton(Messages.getString(key)); if (!StringUtils.isEmpty(tooltipText)) { radioButton.setToolTipText(tooltipText); }//from www . j ava 2s . c o m return radioButton; }
From source file:com.mirth.connect.client.ui.AttachmentExportDialog.java
private void initComponents() { binaryButton = new JRadioButton("Binary"); binaryButton.setSelected(true);//from ww w . j av a2 s . c o m binaryButton.setBackground(Color.white); binaryButton.setFocusable(false); textButton = new JRadioButton("Text"); textButton.setBackground(Color.white); textButton.setFocusable(false); ButtonGroup typeButtonGroup = new ButtonGroup(); typeButtonGroup.add(binaryButton); typeButtonGroup.add(textButton); serverButton = new JRadioButton("Server"); serverButton.setBackground(Color.white); serverButton.setFocusable(false); localButton = new JRadioButton("My Computer"); localButton.setBackground(Color.white); localButton.setSelected(true); localButton.setFocusable(false); browseButton = new MirthButton("Browse..."); localButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { browseButton.setEnabled(true); fileField.setText(null); } }); serverButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { browseButton.setEnabled(false); fileField.setText(null); } }); ButtonGroup locationButtonGroup = new ButtonGroup(); locationButtonGroup.add(serverButton); locationButtonGroup.add(localButton); browseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { browseSelected(); } }); fileField = new JTextField(); exportButton = new JButton("Export"); cancelButton = new JButton("Cancel"); exportButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { export(); } }); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); }
From source file:eu.apenet.dpt.standalone.gui.XsltAdderActionListener.java
public void actionPerformed(ActionEvent e) { JFileChooser xsltChooser = new JFileChooser(); xsltChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (xsltChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = xsltChooser.getSelectedFile(); if (isXSLT(file)) { if (saveXslt(file)) { JRadioButton newButton = new JRadioButton(file.getName()); newButton.addActionListener(new XsltSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXslt().add(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsltPanel(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .addToXsltPanel(Box.createRigidArea(new Dimension(0, 10))); JOptionPane.showMessageDialog(parent, labels.getString("xsltSaved") + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".", labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon); }// w w w . j av a 2 s . c o m } else { JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".", labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon); } } }
From source file:DialogSeparator.java
public FlightReservation() { super("Dialog "); Container c = getContentPane(); c.setLayout(new FlowLayout()); c.add(new DialogSeparator("Options")); ButtonGroup group = new ButtonGroup(); JRadioButton r1 = new JRadioButton("First class"); group.add(r1);/*w w w .j av a 2 s . c om*/ c.add(r1); JRadioButton r2 = new JRadioButton("Business"); group.add(r2); c.add(r2); JRadioButton r3 = new JRadioButton("Coach"); group.add(r3); c.add(r3); c.add(new DialogSeparator()); JButton b3 = new JButton("Exit"); c.add(b3); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setSize(300, 200); setVisible(true); }