List of usage examples for javax.swing JRadioButton JRadioButton
public JRadioButton(String text)
From source file:Main.java
public Main() { this.setLayout(new FlowLayout()); this.add(new JButton("test")); this.add(new JCheckBox("test")); this.add(new JRadioButton("test")); this.add(new JProgressBar(0, 100)); JPanel panel = new JPanel() { @Override//from w ww .j av a 2s.c o m public Dimension getPreferredSize() { return new Dimension(400, 300); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.red); g.fillRect(0, 0, getWidth(), getHeight()); } }; panel.add(new JLabel("Label")); add(panel); setSize(new Dimension(400, 300)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public Main(String title) { super(title); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container contentPane = this.getContentPane(); ButtonGroup group = new ButtonGroup(); small = new JRadioButton("small"); medium = new JRadioButton("medium"); large = new JRadioButton("large"); group.add(small);//from w w w .j a v a 2s . c o m group.add(medium); group.add(large); button = new JButton("Click here."); button.setBounds(100, 50, 100, 50); JPanel center = new JPanel(); center.setLayout(null); center.add(button); contentPane.add(center, BorderLayout.CENTER); JPanel north = new JPanel(); north.add(small); north.add(medium); north.add(large); contentPane.add(north, BorderLayout.NORTH); ChangeSize listener = new ChangeSize(button); small.addItemListener(listener); medium.addItemListener(listener); large.addItemListener(listener); }
From source file:MainClass.java
public MainClass() { theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cp = theFrame.getContentPane();//w ww . ja v a 2 s. co 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:MainClass.java
public MainClass() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); 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); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); undoButton.setEnabled(false); redoButton.setEnabled(false); 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()); } } }); 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()); } } }); 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()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:Main.java
/** * Creates a radio button with all the properties set up front. * /*from www .j ava 2 s .c o m*/ * @param name * The caption of the button. * @param command * The name of the command the listener should look for. * @param isSelected * The condition that should be true if this control is selected. * @param listener * The object listening for commands. * @return A configured radio button. */ public static JRadioButton createRadioButton(String name, String command, boolean isSelected, ActionListener listener) { JRadioButton button; button = new JRadioButton(name); button.setActionCommand(command); button.setSelected(isSelected); button.addActionListener(listener); return button; }
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);/*from ww w. ja va 2 s.c o m*/ cbg.add(ovalButton); 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); }
From source file:UndoableToggleApp2.java
public UndoableToggleApp2() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);/* www .j av a 2s . c om*/ cb.addActionListener(sl); radio.addActionListener(sl); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); undoButton.setEnabled(false); redoButton.setEnabled(false); endButton.setEnabled(false); 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()); } } }); 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()); } } }); endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); 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()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoEndBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:Buttons.java
public void init() { Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(jb);//from ww w .j a v a 2s . com cp.add(new JToggleButton("JToggleButton")); cp.add(new JCheckBox("JCheckBox")); cp.add(new JRadioButton("JRadioButton")); JPanel jp = new JPanel(); jp.setBorder(new TitledBorder("Directions")); jp.add(up); jp.add(down); jp.add(left); jp.add(right); cp.add(jp); }
From source file:CardLayoutDemo.java
public void addCardsToPane(Container pane) { JRadioButton[] rb = new JRadioButton[strings.length]; ButtonGroup group = new ButtonGroup(); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.PAGE_AXIS)); for (int i = 0; i < strings.length; i++) { rb[i] = new JRadioButton("Show component #" + (i + 1)); rb[i].setActionCommand(String.valueOf(i)); rb[i].addActionListener(this); group.add(rb[i]);/*from w w w. j a v a 2s .co m*/ buttons.add(rb[i]); } rb[0].setSelected(true); //Create the panel that contains the "cards". cards = new JPanel(new CardLayout()); for (int i = 0; i < strings.length; i++) { cards.add(createComponent(strings[i]), String.valueOf(i)); } pane.add(buttons, BorderLayout.NORTH); pane.add(cards, BorderLayout.CENTER); }
From source file:SimpleBufferedImageDemo.java
public SimpleBufferedImageDemo() { super();/*from ww w . j ava2 s . c o m*/ Container container = getContentPane(); canvas = new DisplayCanvas(); container.add(canvas); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2, 2)); panel.setBorder(new TitledBorder("Select an Option and Display Image...")); buffButton = new JRadioButton("Buffered"); buffButton.addActionListener(new ButtonListener()); nonBuffButton = new JRadioButton("Non-Buffered", true); nonBuffButton.addActionListener(new ButtonListener()); ButtonGroup group = new ButtonGroup(); group.add(buffButton); group.add(nonBuffButton); displayButton = new JButton("Display"); displayButton.addActionListener(new ButtonListener()); clearButton = new JButton("Clear"); clearButton.addActionListener(new ButtonListener()); panel.add(nonBuffButton); panel.add(buffButton); panel.add(displayButton); panel.add(clearButton); container.add(BorderLayout.SOUTH, panel); addWindowListener(new WindowEventHandler()); pack(); setVisible(true); }