List of usage examples for javax.swing JRadioButton JRadioButton
public JRadioButton(String text)
From source file:edu.ku.brc.specify.config.init.DBLocationPanel.java
/** * Creates a dialog for entering database name and selecting the appropriate driver. *///from w w w .ja v a 2s .com public DBLocationPanel(final JButton nextBtn) { super("Storage", null, nextBtn, null); localDirOK = true; File currentPath = new File(UIRegistry.getAppDataDir() + File.separator + "specify_tmp.tmp"); try { FileUtils.touch(currentPath); currentPath.delete(); } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DBLocationPanel.class, ex); localDirOK = false; } //localDirOK = false ; // XXX TESTING ButtonGroup grp = new ButtonGroup(); useHomeRB = new JRadioButton( "<html>Use your home directory: <b>" + UIRegistry.getUserHomeAppDir() + "</b></html>"); grp.add(useHomeRB); useHomeRB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (browse != null) { browse.setEnabled(false); } updateBtnUI(); } }); int numRows = 3; StringBuilder header = new StringBuilder( "<html>This step requires you to select a storage for the database."); //localDirOK = false; // DEBUG if (localDirOK) { header.append("There are three options:</html>"); useCurrentRB = new JRadioButton( "<html>Use your current directory: <b>" + UIRegistry.getDefaultWorkingPath() + "</b></html>"); grp.add(useCurrentRB); useCurrentRB.setSelected(true); numRows++; } else { header.append( "<br>The database cannot be stored on the media you are currently running Workbench from, "); header.append( "so you can allow it to default to your '<i>home</i>' directory. Or choose a different storage.</html>"); useHomeRB.setSelected(true); } useUserDefinedRB = new JRadioButton("Use other storage:"); grp.add(useUserDefinedRB); useUserDefinedRB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { browse.setEnabled(true); updateBtnUI(); } }); filePath = new JTextField(30); filePath.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { updateBtnUI(); } public void removeUpdate(DocumentEvent e) { updateBtnUI(); } public void changedUpdate(DocumentEvent e) { updateBtnUI(); } }); browse = new BrowseBtnPanel(filePath, true, true); browse.setEnabled(false); CellConstraints cc = new CellConstraints(); JLabel lbl = new JLabel(header.toString()); PanelBuilder cmtBldr = new PanelBuilder(new FormLayout("f:min(300px;p):g", "f:p:g")); cmtBldr.add(lbl, cc.xy(1, 1)); PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p:g", "p:g,2px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", numRows) + ",f:p:g"), this); int row = 1; builder.add(cmtBldr.getPanel(), cc.xywh(1, row, 3, 1)); row += 2; builder.add(useHomeRB, cc.xy(1, row)); row += 2; if (useCurrentRB != null) { builder.add(useCurrentRB, cc.xy(1, row)); row += 2; } builder.add(useUserDefinedRB, cc.xy(1, row)); row += 2; builder.add(browse, cc.xy(1, row)); row += 2; }
From source file:ListTest.java
/** * Makes a radio button to set the layout orientation. * @param label the button label/*from w w w . j a va 2 s .c o m*/ * @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(); } }); }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.DefItemEditorPanel.java
/** * @param numInUseArg//w w w . jav a2s . c o m * @param isRow */ protected void createUI(final int numInUseArg, final boolean isRow) { propsPanel = new RowColDefPanel(item, numInUseArg, isRow); autoPropsPanel = createAutoPropertyPanel(numInUseArg, isRow); cardPanel = new JPanel(cardLayout); cardPanel.add("Auto", autoPropsPanel); cardPanel.add("List", propsPanel); ActionListener action = new ActionListener() { public void actionPerformed(ActionEvent e) { isUsingAuto = autoCB.isSelected(); cardLayout.show(cardPanel, isUsingAuto ? "Auto" : "List"); } }; autoCB = new JRadioButton("Auto"); autoCB.addActionListener(action); listCB = new JRadioButton("List"); listCB.addActionListener(action); ButtonGroup group = new ButtonGroup(); group.add(autoCB); group.add(listCB); autoCB.setSelected(true); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,16px,p,f:p:g", "p")); //$NON-NLS-1$ //$NON-NLS-2$ pb.add(listCB, cc.xy(2, 1)); pb.add(autoCB, cc.xy(4, 1)); add(pb.getPanel(), BorderLayout.NORTH); add(cardPanel, BorderLayout.CENTER); cardLayout.show(cardPanel, "List"); listCB.setSelected(true); isUsingAuto = false; }
From source file:au.org.ala.delta.ui.SearchDialog.java
/** * Create the dialog.// w ww . j a va 2 s.c o m */ public SearchDialog(SearchController controller) { super(UIUtils.getParentFrame(controller.getOwningComponent())); hookInternalFrame(controller.getOwningComponent()); _controller = controller; UIUtils.centerDialog(this, controller.getOwningComponent().getParent()); setTitle(controller.getTitle()); setName(_controller.getTitle()); setBounds(100, 100, 366, 229); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); SingleFrameApplication application = (SingleFrameApplication) Application.getInstance(); ResourceMap messages = application.getContext().getResourceMap(); JLabel lblFind = new JLabel(messages.getString("searchDialog.lblFind")); lblFind.setMinimumSize(new Dimension(30, 0)); textField = new JTextField(); textField.setColumns(10); JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(null, messages.getString("searchDialog.groupDirection"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); buttonGroup = new ButtonGroup(); rdbtnForwards = new JRadioButton(messages.getString("searchDialog.directionForwards")); rdbtnForwards.setSelected(true); buttonGroup.add(rdbtnForwards); rdbtnBackwards = new JRadioButton(messages.getString("searchDialog.directionBackwards")); buttonGroup.add(rdbtnBackwards); contentPanel.setLayout(new MigLayout("", "[growprio 0,grow,left][grow][grow]", "[20px][21px,grow][grow]")); contentPanel.add(lblFind, "cell 0 0,alignx left,aligny top"); contentPanel.add(textField, "cell 1 0 2 1,growx,aligny top"); final JPanel panel_1 = new JPanel(); panel_1.setBorder(new TitledBorder(null, messages.getString("searchDialog.optionsPanelTitle"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); contentPanel.add(panel_1, "cell 0 1 2 1,grow"); panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS)); chckbxMatchCase = new JCheckBox(messages.getString("searchDialog.lblMatchCase")); panel_1.add(chckbxMatchCase); chckbxWrapSearch = new JCheckBox(messages.getString("searchDialog.lblWrapSearch")); panel_1.add(chckbxWrapSearch); chckbxWrapSearch.setSelected(true); contentPanel.add(panel, "cell 2 1,grow"); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(rdbtnForwards); panel.add(rdbtnBackwards); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton findButton = new JButton(messages.getString("searchDialog.btnFindNext")); findButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { findNext(); } }); buttonPane.add(findButton); getRootPane().setDefaultButton(findButton); } { JButton cancelButton = new JButton(messages.getString("searchDialog.btnCancel")); buttonPane.add(cancelButton); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); } } }
From source file:components.TableSelectionDemo.java
private JRadioButton addRadio(String text) { JRadioButton b = new JRadioButton(text); b.addActionListener(this); buttonGroup.add(b);/* w w w .j a v a 2 s. c o m*/ add(b); return b; }
From source file:VoteDialog.java
private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton voteButton = null;/*from w w w.j a v a 2 s . c o m*/ final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("<html>Candidate 1: <font color=red>Sparky the Dog</font></html>"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("<html>Candidate 2: <font color=green>Shady Sadie</font></html>"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("<html>Candidate 3: <font color=blue>R.I.P. McDaniels</font></html>"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton( "<html>Candidate 4: <font color=maroon>Duke the Java<font size=-2><sup>TM</sup></font size> Platform Mascot</font></html>"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } // Select the first button by default. radioButtons[0].setSelected(true); voteButton = new JButton("Vote"); voteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "This candidate is a dog. Invalid vote."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "This candidate is a convicted felon. \nDo you still want to vote for her?", "A Follow-up Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("OK. Keep an eye on your wallet."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no (with customized wording) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No, thanks" }; int n = JOptionPane.showOptionDialog(frame, "This candidate is deceased. \nDo you still want to vote for him?", "A Follow-up Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("I hope you don't expect much from your candidate."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no/cancel (with customized wording) } else if (command == yncCommand) { Object[] options = { "Yes!", "No, I'll pass", "Well, if I must" }; int n = JOptionPane.showOptionDialog(frame, "Duke is a cartoon mascot. \nDo you " + "still want to cast your vote?", "A Follow-up Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Excellent choice."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whatever you say. It's your vote."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to make you vote."); } else { setLabel("It is your civic duty to cast your vote."); } } return; } }); System.out.println("calling createPane"); return createPane(simpleDialogDesc + ":", radioButtons, voteButton); }
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 . ja va2s .c o 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:QandE.LunarPhasesRB.java
private void addWidgets() { /*// w w w . j ava 2s . c om * Create a label for displaying the moon phase images and * put a border around it. */ phaseIconLabel = new JLabel(); phaseIconLabel.setHorizontalAlignment(JLabel.CENTER); phaseIconLabel.setVerticalAlignment(JLabel.CENTER); phaseIconLabel.setVerticalTextPosition(JLabel.CENTER); phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER); phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5))); phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0), phaseIconLabel.getBorder())); //Create radio buttons with lunar phase choices. JRadioButton newButton = new JRadioButton("New"); newButton.setActionCommand("0"); newButton.setSelected(true); JRadioButton waxingCrescentButton = new JRadioButton("Waxing Crescent"); waxingCrescentButton.setActionCommand("1"); JRadioButton firstQuarterButton = new JRadioButton("First Quarter"); firstQuarterButton.setActionCommand("2"); JRadioButton waxingGibbousButton = new JRadioButton("Waxing Gibbous"); waxingGibbousButton.setActionCommand("3"); JRadioButton fullButton = new JRadioButton("Full"); fullButton.setActionCommand("4"); JRadioButton waningGibbousButton = new JRadioButton("Waning Gibbous"); waningGibbousButton.setActionCommand("5"); JRadioButton thirdQuarterButton = new JRadioButton("Third Quarter"); thirdQuarterButton.setActionCommand("6"); JRadioButton waningCrescentButton = new JRadioButton("Waning Crescent"); waningCrescentButton.setActionCommand("7"); // Create a button group and add the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(newButton); group.add(waxingCrescentButton); group.add(firstQuarterButton); group.add(waxingGibbousButton); group.add(fullButton); group.add(waningGibbousButton); group.add(thirdQuarterButton); group.add(waningCrescentButton); // Display the first image. phaseIconLabel.setIcon(new ImageIcon("images/image0.jpg")); phaseIconLabel.setText(""); //Make the radio buttons appear in a center-aligned column. selectPanel.setLayout(new BoxLayout(selectPanel, BoxLayout.PAGE_AXIS)); selectPanel.setAlignmentX(Component.CENTER_ALIGNMENT); //Add a border around the select panel. selectPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Select Phase"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Add a border around the display panel. displayPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Display Phase"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Add image and moon phases radio buttons to select panel. displayPanel.add(phaseIconLabel); selectPanel.add(newButton); selectPanel.add(waxingCrescentButton); selectPanel.add(firstQuarterButton); selectPanel.add(waxingGibbousButton); selectPanel.add(fullButton); selectPanel.add(waningGibbousButton); selectPanel.add(thirdQuarterButton); selectPanel.add(waningCrescentButton); //Listen to events from the radio buttons. newButton.addActionListener(this); waxingCrescentButton.addActionListener(this); firstQuarterButton.addActionListener(this); waxingGibbousButton.addActionListener(this); fullButton.addActionListener(this); waningGibbousButton.addActionListener(this); thirdQuarterButton.addActionListener(this); waningCrescentButton.addActionListener(this); }
From source file:REDemo.java
/** Construct the REDemo object including its GUI */ public REDemo() { super();/*from ww w . j a v a 2 s. c om*/ JPanel top = new JPanel(); top.add(new JLabel("Pattern:", JLabel.RIGHT)); patternTF = new JTextField(20); patternTF.getDocument().addDocumentListener(new PatternListener()); top.add(patternTF); top.add(new JLabel("Syntax OK?")); compiledOK = new JCheckBox(); top.add(compiledOK); ChangeListener cl = new ChangeListener() { public void stateChanged(ChangeEvent ce) { tryMatch(); } }; JPanel switchPane = new JPanel(); ButtonGroup bg = new ButtonGroup(); match = new JRadioButton("Match"); match.setSelected(true); match.addChangeListener(cl); bg.add(match); switchPane.add(match); find = new JRadioButton("Find"); find.addChangeListener(cl); bg.add(find); switchPane.add(find); findAll = new JRadioButton("Find All"); findAll.addChangeListener(cl); bg.add(findAll); switchPane.add(findAll); JPanel strPane = new JPanel(); strPane.add(new JLabel("String:", JLabel.RIGHT)); stringTF = new JTextField(20); stringTF.getDocument().addDocumentListener(new StringListener()); strPane.add(stringTF); strPane.add(new JLabel("Matches:")); matchesTF = new JTextField(3); strPane.add(matchesTF); setLayout(new GridLayout(0, 1, 5, 5)); add(top); add(strPane); add(switchPane); }
From source file:ca.phon.app.session.editor.view.media_player.PlayCustomSegmentDialog.java
private void init() { final FormLayout layout = new FormLayout("10dlu, fill:pref:grow", "pref, pref, pref, pref, pref, pref, pref, pref, pref, pref"); final CellConstraints cc = new CellConstraints(); setLayout(layout);// w w w .j a v a 2s.com final SessionEditor editor = editorRef.get(); final Session session = editor.getSession(); btnGrp = new ButtonGroup(); currentSegmentBtn = new JRadioButton("Current segment"); currentSegmentBtn.addActionListener(radioListener); currentSegmentBtn.setSelected(true); btnGrp.add(currentSegmentBtn); contiguousSegmentBtn = new JRadioButton("Speaker turn"); contiguousSegmentBtn.addActionListener(radioListener); btnGrp.add(contiguousSegmentBtn); // periodBtn = new JRadioButton("Adjacency sequence"); // periodBtn.addActionListener(radioListener); // btnGrp.add(periodBtn); recordRangeBtn = new JRadioButton("Record range"); recordRangeBtn.addActionListener(radioListener); btnGrp.add(recordRangeBtn); rangeField = new JTextField(); rangeField.setText((editor.getCurrentRecordIndex() + 1) + ".." + (editor.getCurrentRecordIndex() + 1)); rangeField.setInputVerifier(new RangeVerifier()); rangeField.setEnabled(false); rangeField.getDocument().addDocumentListener(rangeListener); segmentTimeBtn = new JRadioButton("Time range"); segmentTimeBtn.addActionListener(radioListener); btnGrp.add(segmentTimeBtn); segmentField = new MediaSegmentField(); segmentField.setEnabled(false); updateSegmentTimes(); final DialogHeader header = new DialogHeader("Play Custom Segment", "Play a custom defined segment"); add(header, cc.xyw(1, 1, 2)); add(currentSegmentBtn, cc.xyw(1, 2, 2)); add(contiguousSegmentBtn, cc.xyw(1, 3, 2)); // add(periodBtn, cc.xyw(1, 4, 2)); add(recordRangeBtn, cc.xyw(1, 5, 2)); add(rangeField, cc.xy(2, 6)); add(segmentTimeBtn, cc.xyw(1, 7, 2)); add(segmentField, cc.xy(2, 8)); final ImageIcon playIcon = IconManager.getInstance().getIcon("actions/media-playback-start", IconSize.SMALL); final ImageIcon cancelIcon = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL); final PhonUIAction playAct = new PhonUIAction(this, "onPlay"); playAct.putValue(PhonUIAction.NAME, "Play"); playAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Play segment"); playAct.putValue(PhonUIAction.SMALL_ICON, playIcon); playBtn = new JButton(playAct); final PhonUIAction cancelAct = new PhonUIAction(this, "onCancel"); cancelAct.putValue(PhonUIAction.NAME, "Close"); cancelAct.putValue(PhonUIAction.SMALL_ICON, cancelIcon); cancelBtn = new JButton(cancelAct); final JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); btnPanel.add(cancelBtn); btnPanel.add(playBtn); add(btnPanel, cc.xyw(1, 9, 2)); }