Example usage for javax.swing JCheckBox isSelected

List of usage examples for javax.swing JCheckBox isSelected

Introduction

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

Prototype

public boolean isSelected() 

Source Link

Document

Returns the state of the button.

Usage

From source file:Main.java

public static boolean isCheckBoxModified(JCheckBox checkBox, boolean originalValue) {
    return checkBox.isSelected() != originalValue;
}

From source file:br.usp.poli.lta.cereda.wsn2spa.Utils.java

public static boolean neither(JCheckBox... checkboxes) {
    for (JCheckBox box : checkboxes) {
        if (box.isSelected()) {
            return false;
        }/*from   w  w w .j av a  2 s .  c om*/
    }
    return true;
}

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

/**
 * @param centerPanel//from   w ww .j ava2  s . co  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:OAT.ui.util.UiUtil.java

public static void triggerTextField(JTextField textField, JCheckBox checkBox) {
    if (checkBox.isSelected()) {
        textField.setDisabledTextColor(Color.LIGHT_GRAY);
    }/*from w w  w.j ava2 s . co m*/

    textField.setEnabled(!checkBox.isSelected());
}

From source file:com.diversityarrays.kdxplore.vistool.VisToolbarFactory.java

static public VisToolToolBar create(final String title, final JComponent comp, final Closure<File> snapshotter,
        final VisToolDataProvider visToolDataProvider, boolean floatable, final String[] imageSuffixes) {
    Window window = GuiUtil.getOwnerWindow(comp);

    boolean anyButtons = false;

    final JCheckBox keepOnTop;

    if (window == null) {
        keepOnTop = null;//from  ww  w .  j  av  a 2s  .c  o  m
    } else {
        anyButtons = true;
        keepOnTop = new JCheckBox(Msg.OPTION_KEEP_ON_TOP(), true);

        keepOnTop.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                window.setAlwaysOnTop(keepOnTop.isSelected());
            }
        });
        window.setAlwaysOnTop(keepOnTop.isSelected());

        //         buttons.add(keepOnTop);

        final PropertyChangeListener alwaysOnTopListener = new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                keepOnTop.setSelected(window.isAlwaysOnTop());
            }
        };
        window.addPropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener);

        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                window.removeWindowListener(this);
                window.removePropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener);
            }
        });
    }

    final JButton cameraButton;
    if (snapshotter == null) {
        cameraButton = null;
    } else {
        Action cameraAction = new AbstractAction(Msg.ACTION_SNAPSHOT()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (chooser == null) {
                    chooser = new JFileChooser();
                    chooser.setFileFilter(new FileFilter() {
                        @Override
                        public boolean accept(File f) {
                            if (!f.isFile()) {
                                return true;
                            }
                            String loname = f.getName().toLowerCase();
                            for (String sfx : imageSuffixes) {
                                if (loname.endsWith(sfx)) {
                                    return true;
                                }
                            }
                            return false;
                        }

                        @Override
                        public String getDescription() {
                            return Msg.DESC_IMAGE_FILE();
                        }
                    });
                    chooser.setMultiSelectionEnabled(false);
                    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                }

                if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(comp)) {
                    File file = chooser.getSelectedFile();
                    snapshotter.execute(file);
                }
            }
        };

        ImageIcon icon = loadIcon("camera-24.png"); //$NON-NLS-1$
        if (icon != null) {
            cameraAction.putValue(Action.SMALL_ICON, icon);
            cameraAction.putValue(Action.NAME, null);
        }

        anyButtons = true;
        cameraButton = new JButton(cameraAction);
    }

    final JButton refreshButton;
    if (visToolDataProvider == null) {
        refreshButton = null;
    } else {
        anyButtons = true;

        refreshButton = new JButton(Msg.ACTION_REFRESH());

        ImageIcon icon = loadIcon("refresh-24.png"); //$NON-NLS-1$
        if (icon != null) {
            refreshButton.setIcon(icon);
            // don't remove the name
        }

        refreshButton.setForeground(Color.RED);
        refreshButton.setEnabled(false);

        refreshButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (visToolDataProvider.refreshData()) {
                    refreshButton.setEnabled(false);
                }
            }
        });

        visToolDataProvider.addVisToolDataChangedListener(new VisToolDataChangedListener() {
            @Override
            public void visToolDataChanged(Object source) {
                refreshButton.setEnabled(true);
            }
        });
    }

    VisToolToolBar toolBar = null;

    if (anyButtons) {
        toolBar = new VisToolToolBar(keepOnTop, cameraButton, refreshButton);
        toolBar.setFloatable(floatable);
    }
    return toolBar;

}

From source file:SwingCheckBoxes.java

private void trace(String b, JCheckBox cb) {
    if (cb.isSelected())
        t.append("Box " + b + " Set\n");
    else/*from  www .  j  a v a  2 s  .  c o m*/
        t.append("Box " + b + " Cleared\n");
}

From source file:labr_client.xml.ObjToXML.java

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

    try {/*from  w  w  w .j  a va2s.co  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  w  w w  . j a v  a 2s . 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:CheckBoxState.java

public CheckBoxState() {
    setSize(300, 300);//w w w .  jav a  2s .  c  om
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout(FlowLayout.LEFT));

    JCheckBox checkBox = new JCheckBox("Check me!");
    checkBox.setSelected(true);

    boolean selected = checkBox.isSelected();
    if (selected) {
        System.out.println("Check box state is selected.");
    } else {
        System.out.println("Check box state is not selected.");
    }

    getContentPane().add(checkBox);
}

From source file:Main.java

public Main() {
    setSize(300, 300);// www. j  a  va  2  s. c o m
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout(FlowLayout.LEFT));

    JCheckBox checkBox = new JCheckBox("Check me!");
    checkBox.setSelected(true);

    boolean selected = checkBox.isSelected();
    if (selected) {
        System.out.println("Check box state is selected.");
    } else {
        System.out.println("Check box state is not selected.");
    }

    getContentPane().add(checkBox);
}