List of usage examples for javax.swing JRadioButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:BoxLayoutTest.java
public JRadioButton addRadioButton(JPanel p, ButtonGroup g, String name, boolean selected) { JRadioButton button = new JRadioButton(name, selected); button.addActionListener(this); g.add(button);// w ww. j av a 2 s . co m p.add(button); return button; }
From source file:LNFSwitcher.java
/** Construct a program... */ public LNFSwitcher() { super();/* w w w . j ava 2 s . com*/ theFrame = new JFrame("LNF Switcher"); theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cp = theFrame.getContentPane(); 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(); // System.out.println(defaultLookAndFeel); 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: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); }//from w w w .j a v a 2 s. c o m } else { JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".", labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon); } } }
From source file:TabbedPaneTest.java
public TabbedPaneFrame() { setTitle("TabbedPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); tabbedPane = new JTabbedPane(); // we set the components to null and delay their loading until the tab is shown // for the first time ImageIcon icon = new ImageIcon("yellow-ball.gif"); tabbedPane.addTab("Mercury", icon, null); tabbedPane.addTab("Venus", icon, null); tabbedPane.addTab("Earth", icon, null); tabbedPane.addTab("Mars", icon, null); tabbedPane.addTab("Jupiter", icon, null); tabbedPane.addTab("Saturn", icon, null); tabbedPane.addTab("Uranus", icon, null); tabbedPane.addTab("Neptune", icon, null); tabbedPane.addTab("Pluto", null, null); final int plutoIndex = tabbedPane.indexOfTab("Pluto"); JPanel plutoPanel = new JPanel(); plutoPanel.add(new JLabel("Pluto", icon, SwingConstants.LEADING)); JToggleButton plutoCheckBox = new JCheckBox(); plutoCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tabbedPane.remove(plutoIndex); }/*from w w w . j a va 2s.co m*/ }); plutoPanel.add(plutoCheckBox); tabbedPane.setTabComponentAt(plutoIndex, plutoPanel); add(tabbedPane, "Center"); tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { // check if this tab still has a null component if (tabbedPane.getSelectedComponent() == null) { // set the component to the image icon int n = tabbedPane.getSelectedIndex(); loadTab(n); } } }); loadTab(0); JPanel buttonPanel = new JPanel(); ButtonGroup buttonGroup = new ButtonGroup(); JRadioButton wrapButton = new JRadioButton("Wrap tabs"); wrapButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT); } }); buttonPanel.add(wrapButton); buttonGroup.add(wrapButton); wrapButton.setSelected(true); JRadioButton scrollButton = new JRadioButton("Scroll tabs"); scrollButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); } }); buttonPanel.add(scrollButton); buttonGroup.add(scrollButton); add(buttonPanel, BorderLayout.SOUTH); }
From source file:org.altusmetrum.altosuilib_2.AltosUIEnable.java
public void add_units() { /* Imperial units setting */ /* Add label */ JRadioButton imperial_units = new JRadioButton("Imperial Units", AltosUIPreferences.imperial_units()); imperial_units.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton item = (JRadioButton) e.getSource(); boolean enabled = item.isSelected(); AltosUIPreferences.set_imperial_units(enabled); }// ww w .ja v a 2 s . c o m }); imperial_units.setToolTipText("Use Imperial units instead of metric"); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 1000; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; add(imperial_units, c); }
From source file:eu.apenet.dpt.standalone.gui.XsdAdderActionListener.java
public void actionPerformed(ActionEvent e) { JFileChooser xsdChooser = new JFileChooser(); xsdChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (xsdChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = xsdChooser.getSelectedFile(); if (isXSD(file)) { XsdInfoQueryComponent xsdInfoQueryComponent = new XsdInfoQueryComponent(labels, file.getName()); int result = JOptionPane.showConfirmDialog(parent, xsdInfoQueryComponent, "title", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { if (StringUtils.isEmpty(xsdInfoQueryComponent.getName())) { errorMessage();/* w ww.j a va2 s .co m*/ } else { if (saveXsd(file, xsdInfoQueryComponent.getName(), false, xsdInfoQueryComponent.getXsdVersion(), xsdInfoQueryComponent.getFileType())) { JRadioButton newButton = new JRadioButton(xsdInfoQueryComponent.getName()); newButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXsd().add(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsdPanel(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .addToXsdPanel(Box.createRigidArea(new Dimension(0, 10))); JOptionPane.showMessageDialog(parent, labels.getString("xsdSaved") + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { errorMessage(); } } } } else { errorMessage(); } } }
From source file:IsEDTExample.java
public IsEDTExample() { JTable table = new JTable(tableModel); table.setRowHeight(100);//from w ww . java2 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: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/* w w w .j a va2 s . c o 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:components.TableSelectionDemo.java
private JRadioButton addRadio(String text) { JRadioButton b = new JRadioButton(text); b.addActionListener(this); buttonGroup.add(b);//from w ww .ja v a2 s. c om add(b); return b; }
From source file:ListTest.java
/** * Makes a radio button to set the layout orientation. * @param label the button label//from w w w.ja va2 s .c om * @param orientation the orientation for the list */ private void makeButton(String label, final int orientation) { JRadioButton button = new JRadioButton(label); buttonPanel.add(button); if (group.getButtonCount() == 0) button.setSelected(true); group.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { wordList.setLayoutOrientation(orientation); listPanel.revalidate(); } }); }