Example usage for javax.swing JCheckBox JCheckBox

List of usage examples for javax.swing JCheckBox JCheckBox

Introduction

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

Prototype

public JCheckBox(Action a) 

Source Link

Document

Creates a check box where properties are taken from the Action supplied.

Usage

From source file:SelectionMonitor.java

public SelectionMonitor() {
    JScrollPane pane = new JScrollPane(list);
    add(pane);/*w  w w  .  j a  v  a  2s .c  om*/
    list.addListSelectionListener(new RadioUpdater());

    for (int i = 0; i < label.length; i++) {
        checks[i] = new JCheckBox("Selection " + i);
        add(checks[i]);
    }
}

From source file:SimpleTab.java

public SimpleTab() {
    super("JTabbedPane");
    setSize(200, 200);//from   www. ja v  a  2 s  . c  o m
    Container contents = getContentPane();
    jtp = new JTabbedPane();
    jtp.addTab("Tab1", new JLabel("This is Tab One"));
    jtp.addTab("Tab2", new JButton("This is Tab Two"));
    jtp.addTab("Tab3", new JCheckBox("This is Tab Three"));
    contents.add(jtp);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

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);// ww  w . j av a 2 s  .  c o m
        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:MainClass.java

public MainClass() {
    JToggleButton tog = new JToggleButton("ToggleButton");
    JCheckBox cb = new JCheckBox("CheckBox");
    JRadioButton radio = new JRadioButton("RadioButton");

    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//  ww w.  j  av  a  2  s.com
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.undo();
            } catch (CannotUndoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.redo();
            } catch (CannotRedoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    Box undoRedoBox = new Box(BoxLayout.X_AXIS);
    undoRedoBox.add(Box.createGlue());
    undoRedoBox.add(undoButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(redoButton);
    undoRedoBox.add(Box.createGlue());

    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoBox, BorderLayout.SOUTH);
    setSize(400, 150);
}

From source file:Main.java

/**
 * Makes a new CheckBox with given properties.
 * /*  w  w w.  java  2  s .c  o  m*/
 * @param name
 *            The label of the control.
 * @param command
 *            The name the action listener is looking for.
 * @param isSelected
 *            The condition on which this control is selected.
 * @param listener
 *            The action listener.
 * @return A new CheckBox with proper default properties.
 */
public static JCheckBox createCheckBox(String name, String command, boolean isSelected,
        ActionListener listener) {
    JCheckBox button;
    button = new JCheckBox(name);
    button.setActionCommand(command);
    button.setSelected(isSelected);
    button.addActionListener(listener);
    return button;
}

From source file:EditorDropTarget3.java

public static void main(String[] args) {
    try {//from   ww w  .ja va2 s .  c o  m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    final JFrame f = new JFrame("JEditor Pane Drop Target Example 3");

    final JEditorPane pane = new JEditorPane();

    // Add a drop target to the JEditorPane
    EditorDropTarget3 target = new EditorDropTarget3(pane);

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();
    final JCheckBox editable = new JCheckBox("Editable");
    editable.setSelected(true);
    panel.add(editable);
    editable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEditable(editable.isSelected());
        }
    });

    final JCheckBox enabled = new JCheckBox("Enabled");
    enabled.setSelected(true);
    panel.add(enabled);
    enabled.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEnabled(enabled.isSelected());
        }
    });

    f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER);
    f.getContentPane().add(panel, BorderLayout.SOUTH);
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:UndoableToggleApp2.java

public UndoableToggleApp2() {
    JToggleButton tog = new JToggleButton("ToggleButton");
    JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox");
    JRadioButton radio = new JRadioButton("RadioButton");

    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//from w  ww.  j  av  a  2  s  .c o  m
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    undoButton.setEnabled(false);
    redoButton.setEnabled(false);
    endButton.setEnabled(false);

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.undo();
            } catch (CannotUndoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.redo();
            } catch (CannotRedoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit.end();
            endButton.setEnabled(false);
            undoButton.setEnabled(edit.canUndo());
            redoButton.setEnabled(edit.canRedo());
        }
    });

    Box undoRedoEndBox = new Box(BoxLayout.X_AXIS);
    undoRedoEndBox.add(Box.createGlue());
    undoRedoEndBox.add(undoButton);
    undoRedoEndBox.add(Box.createHorizontalStrut(2));
    undoRedoEndBox.add(redoButton);
    undoRedoEndBox.add(Box.createHorizontalStrut(2));
    undoRedoEndBox.add(endButton);
    undoRedoEndBox.add(Box.createGlue());

    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoEndBox, BorderLayout.SOUTH);
    setSize(400, 150);
}

From source file:Buttons.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(jb);/*from  www. jav a 2 s.  c  o m*/
    cp.add(new JToggleButton("JToggleButton"));
    cp.add(new JCheckBox("JCheckBox"));
    cp.add(new JRadioButton("JRadioButton"));
    JPanel jp = new JPanel();
    jp.setBorder(new TitledBorder("Directions"));
    jp.add(up);
    jp.add(down);
    jp.add(left);
    jp.add(right);
    cp.add(jp);
}

From source file:AddCheckBoxAction.java

public void addNewCheckBox() {
    JCheckBox chBox = new JCheckBox("CheckBox " + (this.checkBoxes.size() + 1));
    chBox.addActionListener(new CheckBoxAction(this.checkBoxes.size() + 1));
    checkBoxes.add(chBox);/*from   w  w  w. j  ava 2 s .  c o  m*/
    add(chBox);
    revalidate();
}

From source file:org.jfree.chart.demo.Bottom_panel.java

/**
 * Create the panel.//from  w  w  w .j av  a 2s  .  c om
 */
public Bottom_panel(ArrayList<Graphic> Grafs, ArrayList<XYSeries> series, int x, int y, int width, int height) {

    graf = Grafs.get(8);
    serie = series;
    setBounds(x, y, width, height);
    setLayout(new GridLayout(0, 4, 2, 0));
    final JCheckBox chckbxNewCheckBox_5 = new JCheckBox("Graph 1");
    chckbxNewCheckBox_5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            XYSeries sr = serie.get(0);

            if (chckbxNewCheckBox_5.isSelected() == true) {

                graf.change_data(serie.get(0), true);
            } else {
                graf.change_data(serie.get(0), false);
            }
        }
    });
    chckbxNewCheckBox_5.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_5);

    final JCheckBox chckbxNewCheckBox_1 = new JCheckBox("Graph2");
    chckbxNewCheckBox_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            XYSeries sr = serie.get(1);

            if (chckbxNewCheckBox_1.isSelected() == true) {

                graf.change_data(serie.get(1), true);
            } else {
                graf.change_data(serie.get(1), false);
            }
        }

    });
    chckbxNewCheckBox_1.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_1);

    final JCheckBox chckbxNewCheckBox_2 = new JCheckBox("Graph 3");
    chckbxNewCheckBox_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(2);

            if (chckbxNewCheckBox_2.isSelected() == true) {

                graf.change_data(serie.get(2), true);
            } else {
                graf.change_data(serie.get(2), false);
            }
        }

    });
    chckbxNewCheckBox_2.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_2);

    final JCheckBox chckbxNewCheckBox = new JCheckBox("Graph 4");
    chckbxNewCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(3);

            if (chckbxNewCheckBox.isSelected() == true) {

                graf.change_data(serie.get(3), true);
            } else {
                graf.change_data(serie.get(3), false);
            }
        }

    });
    chckbxNewCheckBox.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox);

    final JCheckBox chckbxNewCheckBox_3 = new JCheckBox("Graph 5");
    chckbxNewCheckBox_3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(4);

            if (chckbxNewCheckBox_3.isSelected() == true) {

                graf.change_data(serie.get(4), true);
            } else {
                graf.change_data(serie.get(4), false);
            }
        }

    });
    chckbxNewCheckBox_3.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_3);

    final JCheckBox chckbxNewCheckBox_4 = new JCheckBox("Graph 6");
    chckbxNewCheckBox_4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(5);

            if (chckbxNewCheckBox_4.isSelected() == true) {

                graf.change_data(serie.get(5), true);
            } else {
                graf.change_data(serie.get(5), false);
            }
        }
    });
    chckbxNewCheckBox_4.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_4);

    final JCheckBox chckbxNewCheckBox_6 = new JCheckBox("Graph 7");
    chckbxNewCheckBox_6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(6);

            if (chckbxNewCheckBox_6.isSelected() == true) {

                graf.change_data(serie.get(6), true);
            } else {
                graf.change_data(serie.get(6), false);
            }
        }

    });
    chckbxNewCheckBox_6.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_6);

    final JCheckBox chckbxNewCheckBox_7 = new JCheckBox("Graph 8");
    chckbxNewCheckBox_7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(7);

            if (chckbxNewCheckBox_6.isSelected() == true) {

                graf.change_data(serie.get(7), true);
            } else {
                graf.change_data(serie.get(7), false);
            }
        }

    });
    chckbxNewCheckBox_7.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_7);

}