JPanel jPanel = new JPanel(); ButtonGroup group = new ButtonGroup(); btn1 = new JRadioButton("btn1 ");btn1.setSelected(true); btn2 = new JRadioButton("btn2 "); group.add(btn1 ); group.add(btn2 ); jPanel.add(btn1); jPanel.add(btn2).
import java.awt.BorderLayout; import java.awt.FlowLayout; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JRadioButton; public class Rb extends JFrame { Rb (){ JRadioButton male = new JRadioButton("male"); JRadioButton female = new JRadioButton("Female"); ButtonGroup bG = new ButtonGroup(); bG.add(male); bG.add(female); this.setSize(100,200); this.setLayout( new FlowLayout()); this.add(male); this.add(female); male.setSelected(true); this.setVisible(true); } public static void main(String args[]){ Rb j = new Rb(); }
SslModeComponent() { super(); setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); fullModeRadioButton = new JRadioButton("Full Verification"); fullModeRadioButton.putClientProperty("SSL_MODE", AgentBootstrapperArgs.SslMode.FULL); fullModeRadioButton.setToolTipText("Perform a complete SSL verification before connecting to the agent."); noneModeRadioButton = new JRadioButton("No verification"); noneModeRadioButton.putClientProperty("SSL_MODE", AgentBootstrapperArgs.SslMode.NONE); noneModeRadioButton.setToolTipText("Completely disable any SSL verification"); noHostVerifyModeRadioButton = new JRadioButton("Don't verify host"); noHostVerifyModeRadioButton.putClientProperty("SSL_MODE", AgentBootstrapperArgs.SslMode.NO_VERIFY_HOST); noHostVerifyModeRadioButton.setToolTipText("Verify the server certificate, but not the hostname."); ButtonGroup sslModeButtonGroup = new ButtonGroup(); ActionListener actionListener = e -> { JRadioButton b = (JRadioButton) e.getSource(); setSslMode((AgentBootstrapperArgs.SslMode) b.getClientProperty("SSL_MODE")); }; for (JRadioButton button : Arrays.asList(fullModeRadioButton, noneModeRadioButton, noHostVerifyModeRadioButton)) { sslModeButtonGroup.add(button); add(button); button.addActionListener(actionListener); } }
String[] data = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}; JPanel panel = new JPanel(new GridLayout(0, 1)); MyButtonGroup myBtnGrp = new MyButtonGroup(); myBtnGrp.addActionListener(new ActionListener() { JRadioButton radioBtn = new JRadioButton(text); radioBtn.setActionCommand(text); myBtnGrp.add(radioBtn); panel.add(radioBtn); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
buttonsPanel.add(btnExit); JLabel label1 = new JLabel("Choose format:"); label1.setAlignmentX(Component.LEFT_ALIGNMENT); label1.setForeground(Color.white); setPanel = new JPanel(); setPanel.setLayout(new javax.swing.BoxLayout(setPanel, javax.swing.BoxLayout.LINE_AXIS)); setPanel.setOpaque(false); setPanel.add(btnSetFastSearch); small3x3 = new JRadioButton("3x3"); small3x3.setForeground(Color.white); boolean selected3x3 = MageFrame.getPreferences().get(LAYOYT_CONFIG_KEY, MageBook.LAYOUT_3x3).equals(MageBook.LAYOUT_3x3); buttonsPanel.add(small3x3); big4x4 = new JRadioButton("4x4"); big4x4.setForeground(Color.white); big4x4.setSelected(!selected3x3); buttonsPanel.add(big4x4); JPanel buttonPanel = new JPanel(); buttonPanel.setPreferredSize(new Dimension(200, 100)); buttonPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 100));
private JPanel switchBotPanel() { JPanel panel = new JPanel(new FlowLayout()); testBotRadiobutton = new JRadioButton(Messages.getString("BotConfigDialog.testBotRadioButton")); testBotRadiobutton.addActionListener(this); selectBotGroup.add(testBotRadiobutton); panel.add(testBotRadiobutton); princessRadiobutton = new JRadioButton(Messages.getString("BotConfigDialog.princessRadioButton")); princessRadiobutton.addActionListener(this); selectBotGroup.add(princessRadiobutton); princessRadiobutton.setSelected(true); panel.add(princessRadiobutton); return panel; }
final JRadioButton radioStock = new JRadioButton("Stock", true); final JTextField stockField = new JTextField(10); JPanel panel = new JPanel(); panel.add(radioStock); panel.add(stockField);
public class Test { public static void main(final String[] args) { final JPanel panel = new JPanel(); final JRadioButton button1 = new JRadioButton("1"); final JRadioButton button2 = new JRadioButton("2"); panel.add(button1); panel.add(button2); JOptionPane.showMessageDialog(null, panel); } }
private void fillMetrics(String[] metrics, JPanel panel) { if (metrics != null) { MetricActionListener listener = new MetricActionListener(); for (int i = 0; i < metrics.length / 2; i++) { JRadioButton radio = new JRadioButton(metrics[2 * i]); String action = metrics[2 * i]; if (action.endsWith(defaultMarker)) { action = action.substring(0, action.length() - defaultMarker.length()); } radio.setActionCommand(action); radio.setToolTipText(metrics[2 * i + 1]); radio.addActionListener(listener); buttonGroupMetrics.add(radio); panel.add(radio); } } else { panel.add(new JLabel(" None...")); } }
q.setTitle("Tv something?"); JRadioButton button = new JRadioButton("on/off"); button.setSize(100, 40); button.setLocation(q.getWidth()/2 - button.getWidth()/2, q.getHeight()/2 - button.getHeight()/2); q.add(button); q.setVisible(true);
public void addItem(T item, String text, boolean selected) { JRadioButton checkBox = new JRadioButton(text, selected); if (myItemMap.isEmpty()) { checkBox.setSelected(true); if (radioListListener != null) { radioListListener.radioSelectionChanged(0); } } myItemMap.put(item, checkBox); buttonGroup.add(checkBox); //noinspection unchecked ((DefaultListModel) getModel()).addElement(checkBox); }
private JPanel createXPathVersionPanel() { JPanel p = new JPanel(); p.add(new JLabel("XPath Version:")); for (Entry<String, String> values : XPathRule.VERSION_DESCRIPTOR.mappings().entrySet()) { JRadioButton b = new JRadioButton(); b.setText(values.getKey()); b.setActionCommand(b.getText()); if (values.getKey().equals(XPathRule.VERSION_DESCRIPTOR.defaultValue())) { b.setSelected(true); } xpathVersionButtonGroup.add(b); p.add(b); } return p; }
JPanel buttonPanel = new JPanel(); JRadioButton b1 = new JRadioButton("button 1"); JRadioButton b2 = new JRadioButton("button 2"); JRadioButton b3 = new JRadioButton("button 3"); ButtonGroup group = new ButtonGroup(); group.add(b1); group.add(b2); group.add(b3); buttonPanel.add(b1); buttonPanel.add(b2); buttonPanel.add(b3); g.drawImage(image, 0, 0, null); g.dispose(); JLabel imageLabel = new JLabel(new ImageIcon(buffer)); JSplitPane splitPane = new JSplitPane(); splitPane.add(imageLabel, JSplitPane.LEFT); frame.add(spane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500,600); frame.setVisible(true);
getContentPane().add(actionPanel,BorderLayout.NORTH); getContentPane().add(demoPanel,BorderLayout.CENTER); setVisible(true); setTitle("White Space"); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); label1 = new JLabel("This is first line"); label2 = new JLabel("This is second line"); add(label1); if(withGlue){ add(Box.createVerticalGlue()); JRadioButton glueButton = new JRadioButton("With Glue"); glueButton.addActionListener(new glueButtonListener()); add(glueButton); add(Box.createHorizontalStrut(10)); JLabel strutLabel = new JLabel("Strut Value"); add(strutLabel); spinner = new JSpinner(new SpinnerNumberModel(0,0,50,1));
JPanel panel = new JPanel(); frame.getContentPane().add(panel, BorderLayout.NORTH); JRadioButton rdbtnNewRadioButton = new JRadioButton("New radio button"); panel.add(rdbtnNewRadioButton); JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("New radio button"); panel.add(rdbtnNewRadioButton_1); JPanel panel_1 = new JPanel(); frame.getContentPane().add(panel_1, BorderLayout.SOUTH); JLabel lblNewLabel = new JLabel("New label"); panel_1.add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("New label"); panel_1.add(lblNewLabel_1);
public class TravellingSalesmanProblem extends JApplet implements ActionListener { ... ButtonGroup group1 = new ButtonGroup(); JRadioButton radio1Button=new JRadioButton("Brute Force Technique",true); JRadioButton radio2Button=new JRadioButton("Simulated Annealing Technique",false); { group1.add(radio1Button); group1.add(radio2Button); }
private JPanel getRadioButtonsPanel() { JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(createLayout()); for (T o : values) { JRadioButton button = new JRadioButton(o.toString()); button.addItemListener(this); group.add(button); buttonsPanel.add(button); buttonToItem.put(button, o); } if(group.getButtonCount() > 0) { group.getElements().nextElement().setSelected(true); } return buttonsPanel; }
final JPanel panel = new JPanel(); final JScrollPane jsp = new JScrollPane(panel); panel.add(new JRadioButton("First Option")); panel.add(new JRadioButton("Second Option")); panel.add(new JRadioButton("Third Option"));
JPanel contentPanel = getContentPanel(); JPanel modesPanel = new JPanel(new GridLayout(4, 1)); contentPanel.add(modesPanel, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); JLabel label = new JLabel("Sprite mode:"); modesPanel.add(label); ButtonGroup checkboxGroup = new ButtonGroup(); JRadioButton singleCheckbox = new JRadioButton("Single", editor.getEmitter().getSpriteMode() == SpriteMode.single); modesPanel.add(singleCheckbox); checkboxGroup.add(singleCheckbox); singleCheckbox.addItemListener(new ItemListener() { @Override JRadioButton randomCheckbox = new JRadioButton("Random", editor.getEmitter().getSpriteMode() == SpriteMode.random); modesPanel.add(randomCheckbox); checkboxGroup.add(randomCheckbox); randomCheckbox.addItemListener(new ItemListener() { @Override JRadioButton animatedCheckbox = new JRadioButton("Animated", editor.getEmitter().getSpriteMode() == SpriteMode.animated); modesPanel.add(animatedCheckbox); checkboxGroup.add(animatedCheckbox); animatedCheckbox.addItemListener(new ItemListener() { @Override
frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE); JPanel northPanel = new JPanel (new GridLayout (2, 1)); JPanel welcomePanel = new JPanel (new FlowLayout (FlowLayout.CENTER)); welcomePanel.add (new JLabel ("Welcome")); northPanel.add (welcomePanel); JPanel radioPanel = new JPanel (new FlowLayout (FlowLayout.CENTER)); JRadioButton button1 = new JRadioButton ("Button 1", true); JRadioButton button2 = new JRadioButton ("Button 2", false); ButtonGroup group = new ButtonGroup (); group.add (button1); group.add (button2); radioPanel.add (button1); radioPanel.add (button2); JPanel southPanel = new JPanel (new FlowLayout (FlowLayout.CENTER)); southPanel.add (new JLabel ("Whose turn:")); southPanel.add (new JButton ("Reset")); frame.setVisible (true);