Example usage for javax.swing JRadioButton JRadioButton

List of usage examples for javax.swing JRadioButton JRadioButton

Introduction

In this page you can find the example usage for javax.swing JRadioButton JRadioButton.

Prototype

public JRadioButton(String text, Icon icon) 

Source Link

Document

Creates a radio button that has the specified text and image, and that is initially unselected.

Usage

From source file:ui.results.ResultChartPanel.java

/**
 * Creates the choice panel, that is placed above the chart.
 * @return   the choice panel// ww w.j a v a2  s .  c om
 */
protected JPanel createChoicePanel() {
    // The radiobuttons
    JRadioButton line = new JRadioButton("Line Chart", true);
    JRadioButton bar = new JRadioButton("Bar Chart", false);

    line.setActionCommand("line chart");
    bar.setActionCommand("bar chart");

    line.addActionListener(this);
    bar.addActionListener(this);

    // Let the radiobuttons form a group: i.e. only one can be selected.
    ButtonGroup choiceGroup = new ButtonGroup();
    choiceGroup.add(line);
    choiceGroup.add(bar);

    // Joining it all on the panel
    JPanel choicePanel = new JPanel();
    choicePanel.add(line);
    choicePanel.add(bar);

    return choicePanel;
}

From source file:ucar.unidata.idv.control.chart.RangeFilter.java

/**
 * Create property left/right components
 *
 *
 * @param comps List of components for properties dialog
 * @param tabIdx Which tab in the gui// www .  ja v a  2 s . co m
 */
protected void getPropertiesComponents(List comps, int tabIdx) {
    super.getPropertiesComponents(comps, tabIdx);
    if (tabIdx != 0) {
        return;
    }
    comps.add(GuiUtils.rLabel("Type: "));
    lessThanButton = new JRadioButton("Less Than", type == TYPE_LESSTHAN);
    greaterThanButton = new JRadioButton("Greater Than", type == TYPE_GREATERTHAN);
    GuiUtils.buttonGroup(lessThanButton, greaterThanButton);
    comps.add(GuiUtils.left(GuiUtils.hbox(lessThanButton, greaterThanButton)));
    comps.add(GuiUtils.rLabel("Range Value: "));
    comps.add(valueFld = new JTextField("" + rangeValue));
}

From source file:misc.ModalityDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method is invoked from the//from ww w. java2  s .c om
 * event-dispatching thread.
 */
private void createAndShowGUI() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    Insets ins = Toolkit.getDefaultToolkit().getScreenInsets(gc);
    int sw = gc.getBounds().width - ins.left - ins.right;
    int sh = gc.getBounds().height - ins.top - ins.bottom;

    // first document

    // frame f1

    f1 = new JFrame("Book 1 (parent frame)");
    f1.setBounds(32, 32, 300, 200);
    f1.addWindowListener(closeWindow);
    // create radio buttons
    rb11 = new JRadioButton("Biography", true);
    rb12 = new JRadioButton("Funny tale", false);
    rb13 = new JRadioButton("Sonnets", false);
    // place radio buttons into a single group
    ButtonGroup bg1 = new ButtonGroup();
    bg1.add(rb11);
    bg1.add(rb12);
    bg1.add(rb13);
    JButton b1 = new JButton("OK");
    b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // get label of selected radiobutton
            String title = null;
            if (rb11.isSelected()) {
                title = rb11.getText();
            } else if (rb12.isSelected()) {
                title = rb12.getText();
            } else {
                title = rb13.getText();
            }
            // prepend radio button label to dialogs' titles
            d2.setTitle(title + " (modeless dialog)");
            d3.setTitle(title + " (document-modal dialog)");
            d2.setVisible(true);
        }
    });
    Container cp1 = f1.getContentPane();
    // create three containers to improve layouting
    cp1.setLayout(new GridLayout(1, 3));
    // an empty container
    Container cp11 = new Container();
    // a container to layout components
    Container cp12 = new Container();
    // an empty container
    Container cp13 = new Container();
    // add a button into a separate panel
    JPanel p1 = new JPanel();
    p1.setLayout(new FlowLayout());
    p1.add(b1);
    // add radio buttons and the OK button one after another into a single column
    cp12.setLayout(new GridLayout(4, 1));
    cp12.add(rb11);
    cp12.add(rb12);
    cp12.add(rb13);
    cp12.add(p1);
    // add three containers
    cp1.add(cp11);
    cp1.add(cp12);
    cp1.add(cp13);

    // dialog d2

    d2 = new JDialog(f1);
    d2.setBounds(132, 132, 300, 200);
    d2.addWindowListener(closeWindow);
    JLabel l2 = new JLabel("Enter your name: ");
    l2.setHorizontalAlignment(SwingConstants.CENTER);
    tf2 = new JTextField(12);
    JButton b2 = new JButton("OK");
    b2.setHorizontalAlignment(SwingConstants.CENTER);
    b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //pass a name into the document modal dialog
            l3.setText("by " + tf2.getText());
            d3.setVisible(true);
        }
    });
    Container cp2 = d2.getContentPane();
    // add label, text field and button one after another into a single column
    cp2.setLayout(new BorderLayout());
    cp2.add(l2, BorderLayout.NORTH);
    cp2.add(tf2, BorderLayout.CENTER);
    JPanel p2 = new JPanel();
    p2.setLayout(new FlowLayout());
    p2.add(b2);
    cp2.add(p2, BorderLayout.SOUTH);

    // dialog d3

    d3 = new JDialog(d2, "", Dialog.ModalityType.DOCUMENT_MODAL);
    d3.setBounds(232, 232, 300, 200);
    d3.addWindowListener(closeWindow);
    JTextArea ta3 = new JTextArea();
    l3 = new JLabel();
    l3.setHorizontalAlignment(SwingConstants.RIGHT);
    Container cp3 = d3.getContentPane();
    cp3.setLayout(new BorderLayout());
    cp3.add(new JScrollPane(ta3), BorderLayout.CENTER);
    JPanel p3 = new JPanel();
    p3.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p3.add(l3);
    cp3.add(p3, BorderLayout.SOUTH);

    // second document

    // frame f4

    f4 = new JFrame("Book 2 (parent frame)");
    f4.setBounds(sw - 300 - 32, 32, 300, 200);
    f4.addWindowListener(closeWindow);
    // create radio buttons
    rb41 = new JRadioButton("Biography", true);
    rb42 = new JRadioButton("Funny tale", false);
    rb43 = new JRadioButton("Sonnets", false);
    // place radio buttons into a single group
    ButtonGroup bg4 = new ButtonGroup();
    bg4.add(rb41);
    bg4.add(rb42);
    bg4.add(rb43);
    JButton b4 = new JButton("OK");
    b4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // get label of selected radiobutton
            String title = null;
            if (rb41.isSelected()) {
                title = rb41.getText();
            } else if (rb42.isSelected()) {
                title = rb42.getText();
            } else {
                title = rb43.getText();
            }
            // prepend radiobutton label to dialogs' titles
            d5.setTitle(title + " (modeless dialog)");
            d6.setTitle(title + " (document-modal dialog)");
            d5.setVisible(true);
        }
    });
    Container cp4 = f4.getContentPane();
    // create three containers to improve layouting
    cp4.setLayout(new GridLayout(1, 3));
    Container cp41 = new Container();
    Container cp42 = new Container();
    Container cp43 = new Container();
    // add the button into a separate panel
    JPanel p4 = new JPanel();
    p4.setLayout(new FlowLayout());
    p4.add(b4);
    // add radiobuttons and the OK button one after another into a single column
    cp42.setLayout(new GridLayout(4, 1));
    cp42.add(rb41);
    cp42.add(rb42);
    cp42.add(rb43);
    cp42.add(p4);
    //add three containers
    cp4.add(cp41);
    cp4.add(cp42);
    cp4.add(cp43);

    // dialog d5

    d5 = new JDialog(f4);
    d5.setBounds(sw - 400 - 32, 132, 300, 200);
    d5.addWindowListener(closeWindow);
    JLabel l5 = new JLabel("Enter your name: ");
    l5.setHorizontalAlignment(SwingConstants.CENTER);
    tf5 = new JTextField(12);
    tf5.setHorizontalAlignment(SwingConstants.CENTER);
    JButton b5 = new JButton("OK");
    b5.setHorizontalAlignment(SwingConstants.CENTER);
    b5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //pass a name into the document modal dialog
            l6.setText("by " + tf5.getText());
            d6.setVisible(true);
        }
    });
    Container cp5 = d5.getContentPane();
    // add label, text field and button one after another into a single column
    cp5.setLayout(new BorderLayout());
    cp5.add(l5, BorderLayout.NORTH);
    cp5.add(tf5, BorderLayout.CENTER);
    JPanel p5 = new JPanel();
    p5.setLayout(new FlowLayout());
    p5.add(b5);
    cp5.add(p5, BorderLayout.SOUTH);

    // dialog d6

    d6 = new JDialog(d5, "", Dialog.ModalityType.DOCUMENT_MODAL);
    d6.setBounds(sw - 500 - 32, 232, 300, 200);
    d6.addWindowListener(closeWindow);
    JTextArea ta6 = new JTextArea();
    l6 = new JLabel();
    l6.setHorizontalAlignment(SwingConstants.RIGHT);
    Container cp6 = d6.getContentPane();
    cp6.setLayout(new BorderLayout());
    cp6.add(new JScrollPane(ta6), BorderLayout.CENTER);
    JPanel p6 = new JPanel();
    p6.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p6.add(l6);
    cp6.add(p6, BorderLayout.SOUTH);

    // third document

    // frame f7

    f7 = new JFrame("Classics (excluded frame)");
    f7.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    f7.setBounds(32, sh - 200 - 32, 300, 200);
    f7.addWindowListener(closeWindow);
    JLabel l7 = new JLabel("Famous writers: ");
    l7.setHorizontalAlignment(SwingConstants.CENTER);
    // create radio buttons
    rb71 = new JRadioButton("Burns", true);
    rb72 = new JRadioButton("Dickens", false);
    rb73 = new JRadioButton("Twain", false);
    // place radio buttons into a single group
    ButtonGroup bg7 = new ButtonGroup();
    bg7.add(rb71);
    bg7.add(rb72);
    bg7.add(rb73);
    Container cp7 = f7.getContentPane();
    // create three containers to improve layouting
    cp7.setLayout(new GridLayout(1, 3));
    Container cp71 = new Container();
    Container cp72 = new Container();
    Container cp73 = new Container();
    // add the label into a separate panel
    JPanel p7 = new JPanel();
    p7.setLayout(new FlowLayout());
    p7.add(l7);
    // add a label and radio buttons one after another into a single column
    cp72.setLayout(new GridLayout(4, 1));
    cp72.add(p7);
    cp72.add(rb71);
    cp72.add(rb72);
    cp72.add(rb73);
    // add three containers
    cp7.add(cp71);
    cp7.add(cp72);
    cp7.add(cp73);

    // fourth document

    // frame f8

    f8 = new JFrame("Feedback (parent frame)");
    f8.setBounds(sw - 300 - 32, sh - 200 - 32, 300, 200);
    f8.addWindowListener(closeWindow);
    JButton b8 = new JButton("Rate yourself");
    b8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showConfirmDialog(null, "I really like my book", "Question (application-modal dialog)",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        }
    });
    Container cp8 = f8.getContentPane();
    cp8.setLayout(new FlowLayout(FlowLayout.CENTER, 8, 8));
    cp8.add(b8);
}

From source file:de.interactive_instruments.ShapeChange.UI.DefaultDialog.java

private void addRadioButton(JPanel panel, ButtonGroup group, String label, String value, String parameter) {
    JRadioButton radioButton;/*from www. ja va2s  .com*/
    panel.add(radioButton = new JRadioButton(label, parameter.equalsIgnoreCase(value)));
    radioButton.setActionCommand(value);
    group.add(radioButton);
}

From source file:net.sf.jabref.openoffice.AutoDetectPaths.java

private boolean autoDetectPaths() {

    if (OS.WINDOWS) {
        List<File> progFiles = findProgramFilesDir();
        File sOffice = null;//ww w. j  a  v a 2 s .co  m
        List<File> sofficeFiles = new ArrayList<>();
        for (File dir : progFiles) {
            if (fileSearchCancelled) {
                return false;
            }
            sOffice = findFileDir(dir, "soffice.exe");
            if (sOffice != null) {
                sofficeFiles.add(sOffice);
            }
        }
        if (sOffice == null) {
            JOptionPane.showMessageDialog(parent, Localization.lang(
                    "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."),
                    Localization.lang("Could not find OpenOffice/LibreOffice installation"),
                    JOptionPane.INFORMATION_MESSAGE);
            JFileChooser jfc = new JFileChooser(new File("C:\\"));
            jfc.setDialogType(JFileChooser.OPEN_DIALOG);
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                @Override
                public boolean accept(File file) {
                    return file.isDirectory();
                }

                @Override
                public String getDescription() {
                    return Localization.lang("Directories");
                }
            });
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jfc.showOpenDialog(parent);
            if (jfc.getSelectedFile() != null) {
                sOffice = jfc.getSelectedFile();
            }
        }
        if (sOffice == null) {
            return false;
        }

        if (sofficeFiles.size() > 1) {
            // More than one file found
            DefaultListModel<File> mod = new DefaultListModel<>();
            for (File tmpfile : sofficeFiles) {
                mod.addElement(tmpfile);
            }
            JList<File> fileList = new JList<>(mod);
            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            fileList.setSelectedIndex(0);
            FormBuilder b = FormBuilder.create()
                    .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref"));
            b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1);
            b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3);
            b.add(fileList).xy(1, 5);
            int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                    Localization.lang("Choose OpenOffice/LibreOffice executable"),
                    JOptionPane.OK_CANCEL_OPTION);
            if (answer == JOptionPane.CANCEL_OPTION) {
                return false;
            } else {
                sOffice = fileList.getSelectedValue();
            }

        } else {
            sOffice = sofficeFiles.get(0);
        }
        return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe");
    } else if (OS.OS_X) {
        File rootDir = new File("/Applications");
        File[] files = rootDir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName())
                        || "LibreOffice.app".equals(file.getName()))) {
                    rootDir = file;
                    break;
                }
            }
        }
        File sOffice = findFileDir(rootDir, SOFFICE_BIN);
        if (fileSearchCancelled) {
            return false;
        }
        if (sOffice == null) {
            return false;
        } else {
            return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN);
        }
    } else {
        // Linux:
        String usrRoot = "/usr/lib";
        File inUsr = findFileDir(new File(usrRoot), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if (inUsr == null) {
            inUsr = findFileDir(new File("/usr/lib64"), SOFFICE);
            if (inUsr != null) {
                usrRoot = "/usr/lib64";
            }
        }

        if (fileSearchCancelled) {
            return false;
        }
        File inOpt = findFileDir(new File("/opt"), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if ((inUsr != null) && (inOpt == null)) {
            return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
        } else if (inOpt != null) {
            if (inUsr == null) {
                return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
            } else { // Found both
                JRadioButton optRB = new JRadioButton(inOpt.getPath(), true);
                JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false);
                ButtonGroup bg = new ButtonGroup();
                bg.add(optRB);
                bg.add(usrRB);
                FormBuilder b = FormBuilder.create()
                        .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref "));
                b.add(Localization.lang(
                        "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:"))
                        .xy(1, 1);
                b.add(optRB).xy(1, 3);
                b.add(usrRB).xy(1, 5);
                int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                        Localization.lang("Choose OpenOffice/LibreOffice executable"),
                        JOptionPane.OK_CANCEL_OPTION);
                if (answer == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (optRB.isSelected()) {
                    return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
                } else {
                    return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
                }
            }
        }
    }
    return false;
}

From source file:com.t3.macro.api.functions.input.ColumnPanel.java

/** Creates a group of radio buttons. */
public JComponent createRadioControl(VarSpec vs) {
    int listIndex = vs.optionValues.getNumeric("SELECT");
    if (listIndex < 0 || listIndex >= vs.valueList.size())
        listIndex = 0;/* w ww. j  a  va  2 s .  c  om*/
    ButtonGroup bg = new ButtonGroup();
    Box box = (vs.optionValues.optionEquals("ORIENT", "H")) ? Box.createHorizontalBox()
            : Box.createVerticalBox();

    // If the prompt is suppressed by SPAN=TRUE, use it as the border title
    String title = "";
    if (vs.optionValues.optionEquals("SPAN", "TRUE"))
        title = vs.prompt;
    box.setBorder(new TitledBorder(new EtchedBorder(), title));

    int radioCount = 0;
    for (String value : vs.valueList) {
        JRadioButton radio = new JRadioButton(value, false);
        bg.add(radio);
        box.add(radio);
        if (listIndex == radioCount)
            radio.setSelected(true);
        radioCount++;
    }
    return box;
}

From source file:com.eviware.soapui.support.components.SimpleForm.java

public JRadioButton appendRadioButton(String caption, String label, ButtonGroup group, boolean selected) {
    JRadioButton radioButton = new JRadioButton(label, selected);
    radioButton.getAccessibleContext().setAccessibleDescription(caption);
    if (group != null) {
        group.add(radioButton);//from   w w  w  . ja va 2 s .co m
    }
    components.put(caption, radioButton);
    append(caption, radioButton);
    return radioButton;
}

From source file:com.milkdairy.collectionsmodule.CollectionsUpdateFormJPanel.java

public void init() {
    this.setLayout(null);
    System.setProperty("collectionsStoredFormColor", this.color);
    this.setBackground(Color.getColor("collectionsStoredFormColor"));

    this.formerIDL = this.addComponent(formerIDL, milkManagementSystemService.xPoint,
            milkManagementSystemService.yPoint, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.formerIDL.setText("Former ID");
    formerIDTF = this.addComponent(formerIDTF,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth + 20,
            milkManagementSystemService.yPoint, milkManagementSystemService.tfWidth,
            milkManagementSystemService.tflHeight);
    formerIDTF.setEditable(false);//from  ww  w  . j  a va  2 s  . com

    this.formerIDErrorL = this.addComponent(formerIDErrorL,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.formerIDErrorL.setForeground(Color.RED);

    this.formerNameL = this.addComponent(formerNameL, milkManagementSystemService.xPoint,
            milkManagementSystemService.yPoint + 40, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.formerNameL.setText("Former Name");
    formerNameTF = this.addComponent(formerNameTF,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth + 20,
            milkManagementSystemService.yPoint + 40, milkManagementSystemService.tfWidth,
            milkManagementSystemService.tflHeight);
    formerNameTF.setEditable(false);
    this.formerNameErrorL = this.addComponent(formerNameErrorL,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint + 40, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.formerNameErrorL.setForeground(Color.RED);

    this.milkPadL = this.addComponent(milkPadL, milkManagementSystemService.xPoint,
            milkManagementSystemService.yPoint + 80, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.milkPadL.setText("Milk Pad Value");
    milkPadTF = this.addComponent(milkPadTF,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth + 20,
            milkManagementSystemService.yPoint + 80, milkManagementSystemService.tfWidth,
            milkManagementSystemService.tflHeight);
    this.milkPadErrorL = this.addComponent(milkPadErrorL,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint + 80, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.milkPadErrorL.setForeground(Color.RED);

    this.milkValueL = this.addComponent(milkValueL, milkManagementSystemService.xPoint,
            milkManagementSystemService.yPoint + 120, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.milkValueL.setText("Milk Quantity");
    milkValueTF = this.addComponent(milkValueTF,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth + 20,
            milkManagementSystemService.yPoint + 120, milkManagementSystemService.tfWidth,
            milkManagementSystemService.tflHeight);
    this.milkValueErrorL = this.addComponent(milkValueErrorL,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint + 120, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.milkValueErrorL.setForeground(Color.RED);

    this.milkPriceL = this.addComponent(milkPriceL, milkManagementSystemService.xPoint,
            milkManagementSystemService.yPoint + 160, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.milkPriceL.setText("Milk Price");
    milkPriceTF = this.addComponent(milkPriceTF,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth + 20,
            milkManagementSystemService.yPoint + 160, milkManagementSystemService.tfWidth,
            milkManagementSystemService.tflHeight);
    this.milkPriceErrorL = this.addComponent(milkPriceErrorL,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint + 160, milkManagementSystemService.lblWidth,
            milkManagementSystemService.lblHeight);
    this.milkPriceErrorL.setForeground(Color.RED);

    this.saveBtn = this.addComponent(this.saveBtn,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth + 20,
            milkManagementSystemService.yPoint + 200, 80, 30);
    this.saveBtn.setText("Save");
    this.saveBtn.setForeground(Color.BLUE);
    this.add(this.saveBtn);

    this.saveBtn.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {

            milkPriceErrorL.setText("");
            milkPadErrorL.setText("");
            milkValueErrorL.setText("");
            milkPriceErrorL.setText("");
            formerNameErrorL.setText("");
            formerIDErrorL.setText("");
            if ("".equals(formerIDTF.getText())) {
                formerIDErrorL.setText(ERROR_FORM);
            } else if ("".equals(formerNameTF.getText())) {
                formerNameErrorL.setText(ERROR_FORM);
            } else if ("".equals(milkPadTF.getText())) {
                milkPadErrorL.setText(ERROR_FORM);
            } else if ("".equals(milkValueTF.getText())) {
                milkValueErrorL.setText(ERROR_FORM);
            } else if ("".equals(milkPriceTF.getText())) {
                milkPriceErrorL.setText(ERROR_FORM);
            }
            //            else if (formerIDCombo.getSelectedItem() == null) {
            //               System.out.println("Former id selection Error");
            //         }
            //               else if (startdateTimePicker == null) {
            //               System.out.println("date selection Error");
            //            }
            else {
                Milk milk = new Milk();
                milk.setFormerID(formerIDCombo.getSelectedItem().toString());
                milk.setName(formerNameTF.getText());
                milk.setPadValue(milkPadTF.getText());
                milk.setQuantity(milkValueTF.getText());
                milk.setRate(milkPriceTF.getText());
                milk.setDate("dsad");
                System.out.println("Im in Former create and save submit action " + milk.toString());
                //filePersistenceManager.save(milk);
            }
            System.out.println("Im in Former create and update submit action");
        }
    });

    this.resetBtn = this.addComponent(this.resetBtn,
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth + 140,
            milkManagementSystemService.yPoint + 200, 80, 30);
    this.resetBtn.setText("Reset");
    this.resetBtn.setForeground(Color.BLUE);
    this.add(this.resetBtn);

    this.resetBtn.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {

            milkPriceTF.setText("");
            milkPadTF.setText("");
            milkValueTF.setText("");
            milkPriceTF.setText("");
            System.out.println("Im in Former create and update submit action");
        }
    });

    collectionMonthDetailsJP = new CollectionMonthDetailsJPanel();
    collectionMonthDetailsJP.setBounds(
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth * 2
                    + milkManagementSystemService.tfWidth * 2,
            milkManagementSystemService.yPoint,
            (milkManagementSystemService.SCREEN_WIDTH / 2) - milkManagementSystemService.tfWidth / 5, 400);
    this.add(collectionMonthDetailsJP);

    List<String> formerIds = persistenceManager.getFormerValues("id");
    if (!CollectionUtils.isEmpty(formerIds)) {
        ids = new String[formerIds.size()];
        formerIds.toArray(ids);
    }

    formerIDCombo = new JComboBox(ids);
    // has to be editable
    formerIDCombo.setEditable(true);

    // change the editor's document
    new CustomInitialSelectionComboBox(formerIDCombo);

    formerIDCombo.setBounds(
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth * 2
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint, milkManagementSystemService.lblWidth + 20,
            milkManagementSystemService.lblHeight + 10);
    formerIDCombo.setMaximumRowCount(5);
    this.add(formerIDCombo);

    List<String> formerNames = persistenceManager.getFormerValues("name");
    if (!CollectionUtils.isEmpty(formerNames)) {
        names = new String[formerNames.size()];
        formerNames.toArray(names);
    }
    System.out.println("Names1 " + formerNames);
    formerNameCombo = new JComboBox(names);
    // has to be editable
    formerNameCombo.setEditable(true);

    // change the editor's document
    new CustomInitialSelectionComboBox(formerNameCombo);

    //customerIDListScrollPane = new JScrollPane(customerIDCombo);
    formerNameCombo.setBounds(
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth * 2
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint + milkManagementSystemService.lblHeight + 20,
            milkManagementSystemService.lblWidth + 20, milkManagementSystemService.lblHeight + 10);
    formerNameCombo.setMaximumRowCount(5);
    this.add(formerNameCombo);

    UtilDateModel model = new UtilDateModel();
    model.setDate(2016, 04, 16);
    model.setSelected(true);

    Properties p = new Properties();
    p.put("text.today", "Today");
    p.put("text.month", "Month");
    p.put("text.year", "Year");
    JDatePanelImpl datePanel = new JDatePanelImpl(model, p);

    datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter());
    datePicker.setBounds(
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth * 2
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint + milkManagementSystemService.lblHeight + 60,
            milkManagementSystemService.lblWidth + 20, milkManagementSystemService.lblHeight + 5);
    this.add(datePicker);

    am = new JRadioButton("AM", true);
    pm = new JRadioButton("PM");
    //Group the radio buttons.
    ButtonGroup amPmgroup = new ButtonGroup();
    amPmgroup.add(am);
    amPmgroup.add(pm);
    am.setBounds(
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth * 2
                    + milkManagementSystemService.tfWidth + 40,
            milkManagementSystemService.yPoint + milkManagementSystemService.lblHeight + 100,
            milkManagementSystemService.lblWidth / 2, milkManagementSystemService.lblHeight + 5);
    this.add(am);
    pm.setBounds(
            milkManagementSystemService.xPoint + milkManagementSystemService.lblWidth * 2
                    + milkManagementSystemService.tfWidth + 40 + milkManagementSystemService.lblWidth / 2,
            milkManagementSystemService.yPoint + milkManagementSystemService.lblHeight + 100,
            milkManagementSystemService.lblWidth / 2, milkManagementSystemService.lblHeight + 5);
    this.add(pm);

    this.search = this.addComponent(this.search,
            milkManagementSystemService.xPoint + (milkManagementSystemService.lblWidth * 2)
                    + milkManagementSystemService.tfWidth + 60,
            milkManagementSystemService.yPoint + 200, 80, 30);
    this.search.setText("Search");
    this.search.setForeground(Color.BLUE);
    this.add(this.search);

    this.search.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            System.out.println("Im in Former create and update submit action");
            System.out.println("Former id" + (String) formerIDCombo.getSelectedItem());
            System.out.println("Former name" + (String) formerNameCombo.getSelectedItem());
            System.out.println("Am   " + am.isSelected());
            System.out.println("pm   " + pm.isSelected());

            String forID = (String) formerIDCombo.getSelectedItem();
            String forName = (String) formerNameCombo.getSelectedItem();
            String amPMStr = am.isSelected() ? "AM" : "PM";
            String dateTime = DateTimeUtil
                    .convertdateToStringeWithTime((Date) datePicker.getModel().getValue());
            System.out.println("Seleted date " + dateTime);
            List<Collection> collectionList = persistenceManager.getCollectionsBy(forID, forName, amPMStr,
                    dateTime);
            if (!CollectionUtils.isEmpty(collectionList)) {
                Collection searchCollection = collectionList.get(0);
                formerNameTF.setText(searchCollection.getFormerName());
                ;
                formerIDTF.setText(searchCollection.getFormerID());
                ;
                milkPadTF.setText(searchCollection.getMilkPad());
                ;
                milkValueTF.setText(searchCollection.getMilkQuantity());
                ;
                milkPriceTF.setText(searchCollection.getMilkPrice());
                ;
            }
        }
    });

    //      UtilDateModel model = new UtilDateModel();
    //      JDatePanelImpl datePanel = new JDatePanelImpl(model, null);
    //      JDatePickerImpl datePicker = new JDatePickerImpl(datePanel, null);
    //       
    //      this.add(datePicker);
    //      JSpinner timeSpinner = new JSpinner( new SpinnerDateModel() );
    //      JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(timeSpinner, "HH:mm:ss");
    //      timeSpinner.setEditor(timeEditor);
    //      timeSpinner.setValue(new Date()); 
    //      timeSpinner.setBounds();
    //      this.add(timeSpinner);

    //       DateTimePicker dateTimePicker = new DateTimePicker();
    //        dateTimePicker.setFormats( DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.MEDIUM ) );
    //        dateTimePicker.setTimeFormat( DateFormat.getTimeInstance( DateFormat.MEDIUM ) );
    //        dateTimePicker.setDate(new Date());
    //        dateTimePicker.setBounds(milkManagementSystemService.xPoint
    //             + (milkManagementSystemService.lblWidth*2)+milkManagementSystemService.tfWidth+60,
    //             milkManagementSystemService.yPoint + 200, 80, 30);
    //        this.add(dateTimePicker);

}

From source file:com.microsoft.azure.hdinsight.spark.ui.SparkSubmissionContentPanel.java

private void addSelectedArtifactLineItem() {
    final String tipInfo = "The Artifact you want to use.";
    JLabel artifactSelectLabel = new JLabel("Select an Artifact to submit");
    artifactSelectLabel.setToolTipText(tipInfo);

    selectedArtifactComboBox = new ComboBox();
    selectedArtifactComboBox.setToolTipText(tipInfo);

    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()] = new JLabel(
            "Artifact should not be null!");
    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()]
            .setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()].setVisible(false);

    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()] = new JLabel(
            "Could not find the local jar package for Artifact");
    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()]
            .setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()].setVisible(false);

    selectedArtifactTextField = new TextFieldWithBrowseButton();
    selectedArtifactTextField.setToolTipText("Artifact from local jar package.");
    selectedArtifactTextField.setEditable(true);
    selectedArtifactTextField.setEnabled(false);
    selectedArtifactTextField.getTextField().getDocument().addDocumentListener(new DocumentListener() {
        @Override//  w w  w  .j  a v a 2s. c  o  m
        public void insertUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2,
                    !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2,
                    !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2,
                    !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }
    });

    selectedArtifactTextField.getButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true,
                    false);
            chooserDescriptor.setTitle("Select Local Artifact File");
            VirtualFile chooseFile = FileChooser.chooseFile(chooserDescriptor, null, null);
            if (chooseFile != null) {
                String path = chooseFile.getPath();
                if (path.endsWith("!/")) {
                    path = path.substring(0, path.length() - 2);
                }
                selectedArtifactTextField.setText(path);
            }
        }
    });

    intelliJArtifactRadioButton = new JRadioButton("Artifact from IntelliJ project:", true);
    localArtifactRadioButton = new JRadioButton("Artifact from local disk:", false);

    intelliJArtifactRadioButton.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectedArtifactComboBox.setEnabled(true);
                selectedArtifactTextField.setEnabled(false);
                mainClassTextField.setButtonEnabled(true);

                setVisibleForFixedErrorMessageLabel(2, false);

                if (selectedArtifactComboBox.getItemCount() == 0) {
                    setVisibleForFixedErrorMessageLabel(2, true);
                }
            }
        }
    });

    localArtifactRadioButton.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectedArtifactComboBox.setEnabled(false);
                selectedArtifactTextField.setEnabled(true);
                mainClassTextField.setButtonEnabled(false);

                setVisibleForFixedErrorMessageLabel(1, false);

                if (StringHelper.isNullOrWhiteSpace(selectedArtifactTextField.getText())) {
                    setVisibleForFixedErrorMessageLabel(2, true);
                }
            }
        }
    });

    ButtonGroup group = new ButtonGroup();
    group.add(intelliJArtifactRadioButton);
    group.add(localArtifactRadioButton);

    intelliJArtifactRadioButton.setSelected(true);

    add(artifactSelectLabel, new GridBagConstraints(0, ++displayLayoutCurrentRow, 0, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin, margin, 0, margin), 0, 0));

    add(intelliJArtifactRadioButton,
            new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST,
                    GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0));

    add(selectedArtifactComboBox,
            new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST,
                    GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0));

    add(errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()],
            new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST,
                    GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));

    add(localArtifactRadioButton,
            new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST,
                    GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0));

    add(selectedArtifactTextField,
            new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 0, 0, GridBagConstraints.WEST,
                    GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0));
    add(errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()],
            new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST,
                    GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));
}

From source file:net.rptools.maptool.launcher.MapToolLauncher.java

private JPanel buildLanguagePanel() {
    final JPanel langPanel = new JPanel();
    langPanel.setLayout(new BorderLayout());

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(0, 1));
    buttonPanel.setBorder(// ww  w.j a va 2  s .c o m
            new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.langPanel.border"))); //$NON-NLS-1$

    String[] localeArray = locales.keySet().toArray(new String[0]);
    Arrays.sort(localeArray);

    ActionListener localeUpdate = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            mapToolLocale = e.getActionCommand();
            // Setting the language won't work without reinitalizing the interface.
            // Instead, we just save it and use it for MapTool.
            //            CopiedFromOtherJars.setLanguage(mapToolLocale);
            updateCommand();
        }
    };
    // Always set the first button ("Default Locale") to true and let one of the others change it, if needed.
    JRadioButton jrb = new JRadioButton(CopiedFromOtherJars.getText("msg.info.defaultLocale"), true);
    jrb.setActionCommand(EMPTY);
    langGroup.add(jrb);
    buttonPanel.add(jrb);
    jrb.addActionListener(localeUpdate);

    for (String locale : localeArray) {
        String name = locale + " - " + locales.get(locale);
        jrb = new JRadioButton(name);
        jrb.setActionCommand(locale);
        jrb.addActionListener(localeUpdate);
        langGroup.add(jrb);
        buttonPanel.add(jrb);
        if (mapToolLocale.equalsIgnoreCase(locale))
            jrb.setSelected(true);
    }
    langPanel.add(buttonPanel, BorderLayout.NORTH);
    return langPanel;
}