Example usage for javax.swing JCheckBox getText

List of usage examples for javax.swing JCheckBox getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the button's text.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();

    JPanel entreePanel = new JPanel();
    final ButtonGroup entreeGroup = new ButtonGroup();
    JRadioButton radioButton;/* ww  w . jav a 2  s.com*/
    entreePanel.add(radioButton = new JRadioButton("A"));
    radioButton.setActionCommand("A");
    entreeGroup.add(radioButton);
    entreePanel.add(radioButton = new JRadioButton("B"));
    radioButton.setActionCommand("B");
    entreeGroup.add(radioButton);
    entreePanel.add(radioButton = new JRadioButton("C", true));
    radioButton.setActionCommand("C");
    entreeGroup.add(radioButton);

    final JPanel condimentsPanel = new JPanel();
    condimentsPanel.add(new JCheckBox("Ketchup"));
    condimentsPanel.add(new JCheckBox("Mustard"));
    condimentsPanel.add(new JCheckBox("Pickles"));

    JPanel orderPanel = new JPanel();
    JButton orderButton = new JButton("Place Order");
    orderPanel.add(orderButton);

    frame.setLayout(new GridLayout(3, 1));
    frame.add(entreePanel);
    frame.add(condimentsPanel);
    frame.add(orderPanel);

    orderButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String entree = entreeGroup.getSelection().getActionCommand();
            System.out.println(entree + " sandwich");
            Component[] components = condimentsPanel.getComponents();
            for (Component c : components) {
                JCheckBox cb = (JCheckBox) c;
                if (cb.isSelected())
                    System.out.println("With " + cb.getText());
            }
        }
    });

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JCheckBox checkbox = new JCheckBox();

    String label = "<html><table cellpadding=0><tr><td><img src=file:" + "icon.gif" + "/></td><td width=" + 3
            + "><td>"

            // Retrieve the current label text
            + checkbox.getText() + "</td></tr></table></html>";

    // Add the icon
    checkbox.setText(label);/*www .  j  a  va2s.  c om*/

}

From source file:com.surenpi.autotest.suite.SuiteRunnerLauncher.java

/**
 * @param centerPanel//from w  w w  . j  ava  2  s  .c  o  m
 * @param urlList
 */
private static void createItemsPanel(JPanel centerPanel, List<URL> urlList) {
    JPanel itemsPanel = new JPanel();
    centerPanel.add(itemsPanel, BorderLayout.CENTER);

    if (CollectionUtils.isEmpty(urlList)) {
        return;
    }

    for (URL url : urlList) {
        String text = url.getFile();
        JCheckBox box = new JCheckBox(new File(text).getName());
        box.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JCheckBox source = (JCheckBox) e.getSource();
                if (source.isSelected()) {
                    runnerList.add(source.getText());
                } else {
                    runnerList.remove(source.getText());
                }
            }
        });

        itemsPanel.add(box);
    }
}

From source file:labr_client.xml.ObjToXML.java

public static void saveProfile(Component[] comps, String profile) {

    try {/*from ww w  .  j a  va  2 s.  c o m*/
        if (comps != null) {
            JAXBContext context = JAXBContext.newInstance(LabrRequest.class);
            Marshaller m = context.createMarshaller();
            //for pretty-print XML in JAXB
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            LabrRequest request = new LabrRequest();
            for (Component comp : comps) {

                if (comp.getName() != null) {

                    if (comp.getName().equals("name")) {
                        request.patient.name.setValue(((JTextField) comp).getText());
                        request.patient.name.setX(comp.getX());
                        request.patient.name.setY(comp.getY());
                        request.patient.name.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("firstName")) {
                        request.patient.firstName.setValue(((JTextField) comp).getText());
                        request.patient.firstName.setX(comp.getX());
                        request.patient.firstName.setY(comp.getY());
                        request.patient.firstName.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("birthDate")) {
                        request.patient.birthDate.setValue(((JFormattedTextField) comp).getText());
                        request.patient.birthDate.setX(comp.getX());
                        request.patient.birthDate.setY(comp.getY());
                        request.patient.birthDate.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("gender")) {
                        request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.gender.setX(comp.getX());
                        request.patient.gender.setY(comp.getY());
                    } else if (comp.getName().equals("straatAndNumber")) {
                        request.patient.straatAndNumber.setValue(((JTextField) comp).getText());
                        request.patient.straatAndNumber.setX(comp.getX());
                        request.patient.straatAndNumber.setY(comp.getY());
                        request.patient.straatAndNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("zip")) {
                        request.patient.zip.setValue(((JTextField) comp).getText());
                        request.patient.zip.setX(comp.getX());
                        request.patient.zip.setY(comp.getY());
                        request.patient.zip.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("city")) {
                        request.patient.city.setValue(((JTextField) comp).getText());
                        request.patient.city.setX(comp.getX());
                        request.patient.city.setY(comp.getY());
                        request.patient.city.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("country")) {
                        request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.country.setX(comp.getX());
                        request.patient.country.setY(comp.getY());
                    } else if (comp.getName().equals("nationalNumber")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("Save")) {
                        JButton jbut = (JButton) comp;
                        ImageIcon icon = (ImageIcon) jbut.getIcon();
                        request.buttons.save.setX(comp.getX());
                        request.buttons.save.setY(comp.getY());
                        request.buttons.save.setValue("Save");
                        if (icon != null) {
                            request.buttons.save.setIcon(icon.getDescription());
                        }
                    } else if (comp.getName().equals("Search")) {
                    } else if (comp.getName().equals("saveAndSend")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("print")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else {
                        Class<? extends Component> c = comp.getClass();
                        if (c.getSimpleName().equals("JLabel")) {
                            JLabel lbl = (JLabel) comp;
                            LabrXMLLabel l = new LabrXMLLabel();
                            l.setColor(String.valueOf(lbl.getForeground().getRGB()));
                            l.setSize(lbl.getFont().getSize());
                            l.setId(lbl.getName());
                            l.setValue(lbl.getText());
                            l.setX(lbl.getX());
                            l.setY(lbl.getY());
                            request.labels.getLabel().add(l);
                        }
                        ;
                        if (c.getSimpleName().equals("JCheckBox")) {
                            JCheckBox chbx = (JCheckBox) comp;
                            LabrXMLRequest req = new LabrXMLRequest();
                            req.setX(chbx.getX());
                            req.setY(chbx.getY());
                            req.setLoinc(chbx.getName());
                            req.setValue(chbx.getText());
                            req.setSelected(chbx.isSelected());
                            request.requests.getRequest().add(req);
                        }
                        ;
                        if (c.getSimpleName().equals("JTextBox")) {

                        }
                        ;
                    }
                }

            }
            m.marshal(request, new File(PublicVars.getUserData()[9] + "\\" + profile + ".xml"));
        }
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}

From source file:labr_client.xml.ObjToXML.java

public static LabrRequest saveLabrRequest(Component[] comps) {

    try {//from   ww w .jav a 2 s.c o m
        if (comps != null) {
            JAXBContext context = JAXBContext.newInstance(LabrRequest.class);
            Marshaller m = context.createMarshaller();
            //for pretty-print XML in JAXB
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            LabrRequest request = new LabrRequest();
            for (Component comp : comps) {

                if (comp.getName() != null) {

                    if (comp.getName().equals("name")) {
                        request.patient.name.setValue(((JTextField) comp).getText());
                        request.patient.name.setX(comp.getX());
                        request.patient.name.setY(comp.getY());
                        request.patient.name.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("firstName")) {
                        request.patient.firstName.setValue(((JTextField) comp).getText());
                        request.patient.firstName.setX(comp.getX());
                        request.patient.firstName.setY(comp.getY());
                        request.patient.firstName.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("birthDate")) {
                        request.patient.birthDate.setValue(((JFormattedTextField) comp).getText());
                        request.patient.birthDate.setX(comp.getX());
                        request.patient.birthDate.setY(comp.getY());
                        request.patient.birthDate.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("gender")) {
                        request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.gender.setX(comp.getX());
                        request.patient.gender.setY(comp.getY());
                    } else if (comp.getName().equals("straatAndNumber")) {
                        request.patient.straatAndNumber.setValue(((JTextField) comp).getText());
                        request.patient.straatAndNumber.setX(comp.getX());
                        request.patient.straatAndNumber.setY(comp.getY());
                        request.patient.straatAndNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("zip")) {
                        request.patient.zip.setValue(((JTextField) comp).getText());
                        request.patient.zip.setX(comp.getX());
                        request.patient.zip.setY(comp.getY());
                        request.patient.zip.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("city")) {
                        request.patient.city.setValue(((JTextField) comp).getText());
                        request.patient.city.setX(comp.getX());
                        request.patient.city.setY(comp.getY());
                        request.patient.city.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("country")) {
                        request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.country.setX(comp.getX());
                        request.patient.country.setY(comp.getY());
                    } else if (comp.getName().equals("nationalNumber")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("Save")) {
                        JButton jbut = (JButton) comp;
                        ImageIcon icon = (ImageIcon) jbut.getIcon();
                        request.buttons.save.setX(comp.getX());
                        request.buttons.save.setY(comp.getY());
                        request.buttons.save.setValue("Save");
                        if (icon != null) {
                            request.buttons.save.setIcon(icon.getDescription());
                        }
                    } else if (comp.getName().equals("Search")) {
                    } else if (comp.getName().equals("saveAndSend")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("print")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else {
                        Class<? extends Component> c = comp.getClass();
                        if (c.getSimpleName().equals("JLabel")) {
                            JLabel lbl = (JLabel) comp;
                            LabrXMLLabel l = new LabrXMLLabel();
                            l.setColor(String.valueOf(lbl.getForeground().getRGB()));
                            l.setSize(lbl.getFont().getSize());
                            l.setId(lbl.getName());
                            l.setValue(lbl.getText());
                            l.setX(lbl.getX());
                            l.setY(lbl.getY());
                            request.labels.getLabel().add(l);
                        }
                        ;
                        if (c.getSimpleName().equals("JCheckBox")) {
                            JCheckBox chbx = (JCheckBox) comp;
                            LabrXMLRequest req = new LabrXMLRequest();
                            req.setX(chbx.getX());
                            req.setY(chbx.getY());
                            req.setLoinc(chbx.getName());
                            req.setValue(chbx.getText());
                            req.setSelected(chbx.isSelected());
                            request.requests.getRequest().add(req);
                        }
                        ;
                        if (c.getSimpleName().equals("JTextBox")) {

                        }
                        ;
                    }
                }
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmm");
            String date = dateFormat.format(Calendar.getInstance().getTime());
            request.attributes.setTitle("LABR-" + PublicVars.getUserData()[5] + "-" + date);
            return request;
        }
        return null;
    } catch (JAXBException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:ToolBarwithCheckBox.java

public ToolbarPanel() {
    setLayout(new BorderLayout());
    JToolBar toolbar = new JToolBar();
    for (int i = 1; i < 4; i++) {
        JCheckBox cbox = new JCheckBox("Checkbox #" + i);
        toolbar.add(cbox);//  w  w  w  .  j  a v  a2 s .c  om
        cbox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JCheckBox source = (JCheckBox) (e.getSource());
                System.out.println("Toolbar " + source.getText());
            }
        });
    }

    add(toolbar, BorderLayout.NORTH);
}

From source file:Main.java

public void itemStateChanged(ItemEvent ie) {
    JCheckBox cb = (JCheckBox) ie.getItem();
    int state = ie.getStateChange();
    if (state == ItemEvent.DESELECTED) {
        System.out.println(cb.getText() + " DESELECTED");
    }//  w w  w  . jav a 2  s  .c  o  m
}

From source file:Main.java

public void itemStateChanged(ItemEvent ie) {
    JCheckBox cb = (JCheckBox) ie.getItem();
    int state = ie.getStateChange();
    if (state == ItemEvent.SELECTED) {
        System.out.println(cb.getText() + " selected");
    } else {// w  ww  .ja va  2  s  . co  m
        System.out.println(cb.getText() + " cleared");
    }
}

From source file:Main.java

public void itemStateChanged(ItemEvent ie) {
    JCheckBox cb = (JCheckBox) ie.getItem();

    if (ie.getStateChange() == ItemEvent.SELECTED)
        System.out.println(cb.getText() + " selected.");
    else//from   w  w  w.j a  v  a  2s  .  com
        System.out.println(cb.getText() + " cleared.");

    if (jcbOption1.isSelected())
        System.out.println("1");
    else if (jcbOption2.isSelected())
        System.out.println("2");
    else if (jcbOption3.isSelected())
        System.out.println("3");
    else
        System.out.println("None");
}

From source file:Main.java

public void itemStateChanged(ItemEvent ie) {
    JCheckBox cb = (JCheckBox) ie.getItem();
    int state = ie.getStateChange();
    if (state == ItemEvent.SELECTED)
        System.out.println(cb.getText() + " selected");
    else/*from   w w  w  .j  av a  2  s  .c o  m*/
        System.out.println(cb.getText() + " cleared");
}