List of usage examples for javax.swing JRadioButton setMnemonic
@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic") public void setMnemonic(int mnemonic)
From source file:Main.java
public static void main(String[] args) { JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); button2.setMnemonic(KeyEvent.VK_G); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);//w w w .j a v a 2 s .c o m colorButtonGroup.add(button2); colorButtonGroup.add(button3); button1.setSelected(true); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JRadioButton rb1 = new JRadioButton("Male"); rb1.setMnemonic(KeyEvent.VK_M); rb1.setActionCommand("Male"); rb1.setSelected(true);//from w w w. ja va 2 s .com JRadioButton rb2 = new JRadioButton("Female"); rb2.setMnemonic(KeyEvent.VK_F); rb2.setActionCommand("Female"); rb2.setSelected(true); ButtonGroup bg = new ButtonGroup(); bg.add(rb1); bg.add(rb2); JPanel jp = new JPanel(); jp.add(rb1); jp.add(rb2); getContentPane().add(jp); pack(); setVisible(true); }
From source file:RadioButtonDemo.java
public RadioButtonDemo() { super(new BorderLayout()); //Create the radio buttons. JRadioButton birdButton = new JRadioButton(birdString); birdButton.setMnemonic(KeyEvent.VK_B); birdButton.setActionCommand(birdString); birdButton.setSelected(true);// www .j ava2 s . c o m JRadioButton catButton = new JRadioButton(catString); catButton.setMnemonic(KeyEvent.VK_C); catButton.setActionCommand(catString); JRadioButton dogButton = new JRadioButton(dogString); dogButton.setMnemonic(KeyEvent.VK_D); dogButton.setActionCommand(dogString); JRadioButton rabbitButton = new JRadioButton(rabbitString); rabbitButton.setMnemonic(KeyEvent.VK_R); rabbitButton.setActionCommand(rabbitString); JRadioButton pigButton = new JRadioButton(pigString); pigButton.setMnemonic(KeyEvent.VK_P); pigButton.setActionCommand(pigString); //Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(birdButton); group.add(catButton); group.add(dogButton); group.add(rabbitButton); group.add(pigButton); //Register a listener for the radio buttons. birdButton.addActionListener(this); catButton.addActionListener(this); dogButton.addActionListener(this); rabbitButton.addActionListener(this); pigButton.addActionListener(this); //Set up the picture label. picture = new JLabel(createImageIcon("images/" + birdString + ".gif")); //The preferred size is hard-coded to be the width of the //widest image and the height of the tallest image. //A real program would compute this. picture.setPreferredSize(new Dimension(177, 122)); //Put the radio buttons in a column in a panel. JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(birdButton); radioPanel.add(catButton); radioPanel.add(dogButton); radioPanel.add(rabbitButton); radioPanel.add(pigButton); add(radioPanel, BorderLayout.LINE_START); add(picture, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:org.nuclos.client.ui.OptionGroup.java
private void addRadioButton(String sLabel, String sMnemonic, String sValue) { final JRadioButton radiobtn = new JRadioButton(sLabel); if (sMnemonic != null && sMnemonic.length() > 0) { radiobtn.setMnemonic(sMnemonic.charAt(0)); }/*from www .j av a 2 s . com*/ radiobtn.getModel().setActionCommand(sValue); radiobtn.getModel().setGroup(bg); radiobtn.addActionListener(actionListener); radiobtn.setEnabled(this.isEnabled()); MouseListener[] mls = getMouseListeners(); for (int i = 0; i < mls.length; i++) { radiobtn.addMouseListener(mls[i]); } bg.add(radiobtn); this.add(radiobtn); }