List of usage examples for javax.swing JCheckBox JCheckBox
public JCheckBox(Action a)
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Selecting CheckBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox checkBox = new JCheckBox("A"); // Define ChangeListener ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { AbstractButton abstractButton = (AbstractButton) changeEvent.getSource(); ButtonModel buttonModel = abstractButton.getModel(); boolean armed = buttonModel.isArmed(); boolean pressed = buttonModel.isPressed(); boolean selected = buttonModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); }// ww w. j av a 2 s.c o m }; // Attach Listeners checkBox.addChangeListener(changeListener); checkBox.setMnemonic(KeyEvent.VK_S); frame.add(checkBox, BorderLayout.NORTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] ITEMS1 = { "one", "two", "three", "four", "five" }; String[] ITEMS2 = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }; JPanel northPanel = new JPanel(); northPanel.add(new JCheckBox("Reminder")); northPanel.add(new JComboBox(ITEMS1)); northPanel.add(new JComboBox(ITEMS2)); JPanel p = new JPanel(new BorderLayout()); p.add(northPanel, BorderLayout.NORTH); p.add(new JScrollPane(new JTextArea(8, 30)), BorderLayout.CENTER); JFrame frame = new JFrame(); frame.getContentPane().add(p);/*from w ww . j ava2 s . c o m*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Action action = new ShowAction(); JCheckBox button = new JCheckBox(action); frame.add(button, BorderLayout.CENTER); frame.setSize(350, 150);//from w w w. j av a 2 s.c o m frame.setVisible(true); }
From source file:TreeEditJCheckBox.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Properties props = System.getProperties(); JTree tree = new JTree(props); JCheckBox checkBox = new JCheckBox("To be or not to be"); TreeCellEditor editor = new DefaultCellEditor(checkBox); tree.setEditable(true);/* w ww. j a va2s. c o m*/ tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setLayout(new OverlayLayout(panel)); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add("1", new JTextField("one")); tabbedPane.add("2", new JTextField("two")); tabbedPane.setAlignmentX(1.0f);//from w w w . j a v a 2 s . co m tabbedPane.setAlignmentY(0.0f); JCheckBox checkBox = new JCheckBox("Add tab"); checkBox.setOpaque(false); checkBox.setAlignmentX(1.0f); checkBox.setAlignmentY(0.0f); panel.add(checkBox); panel.add(tabbedPane); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setSize(400, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setLayout(new OverlayLayout(panel)); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add("1", new JTextField("one")); tabbedPane.add("2", new JTextField("two")); tabbedPane.setAlignmentX(1.0f);/* w w w. j a v a 2 s . c o m*/ tabbedPane.setAlignmentY(0.0f); JCheckBox checkBox = new JCheckBox("Check Me"); checkBox.setOpaque(false); checkBox.setAlignmentX(1.0f); checkBox.setAlignmentY(0.0f); panel.add(checkBox); panel.add(tabbedPane); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setLocationByPlatform(true); frame.setSize(400, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame("This is BOX LAYOUT"); JPanel panel1 = new JPanel(); panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS)); panel1.setBackground(Color.yellow); JPanel panel2 = new JPanel(); panel2.setLayout(new FlowLayout()); panel2.setBackground(Color.ORANGE); for (int i = 0; i < 5; i++) panel1.add(new JCheckBox("CheckBox " + (i + 1))); f.add(panel1, BorderLayout.WEST); f.add(panel2, BorderLayout.CENTER); f.setVisible(true);/*from www. j a va2 s. c o m*/ f.setSize(300, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:FlatCheckBox.java
public static void main(String args[]) { JFrame frame = new JFrame("Flat CheckBox Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Pizza Toppings"); panel.setBorder(border);// w w w . ja v a 2 s .c o m JCheckBox check = new JCheckBox("Anchovies"); check.setBorderPaintedFlat(true); panel.add(check); check = new JCheckBox("Garlic"); panel.add(check); check = new JCheckBox("Onions"); check.setBorderPaintedFlat(true); panel.add(check); check = new JCheckBox("Pepperoni"); panel.add(check); check = new JCheckBox("Spinach"); check.setBorderPaintedFlat(true); panel.add(check); JButton button = new JButton("Submit"); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String title = (args.length == 0 ? "CheckBox Sample" : args[0]); JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Pizza Toppings"); panel.setBorder(border);//from www. ja v a 2 s . c om JCheckBox check = new JCheckBox("Anchovies"); panel.add(check); check = new JCheckBox("Garlic"); panel.add(check); check = new JCheckBox("Onions"); panel.add(check); check = new JCheckBox("Pepperoni"); panel.add(check); check = new JCheckBox("Spinach"); panel.add(check); JButton button = new JButton("Submit"); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.setSize(240, 250);//www .jav a 2 s . c o m f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane jscrlpLabel = new JScrollPane( new JLabel("<html>A<br>B<br>C<br>D<br>E<br>F<br>G<br>H<br></html>.")); jscrlpLabel.setPreferredSize(new Dimension(200, 100)); JLabel label = new JLabel("Option"); JCheckBox a = new JCheckBox("A"); JCheckBox b = new JCheckBox("B"); JCheckBox c = new JCheckBox("C"); JCheckBox d = new JCheckBox("D"); JCheckBox e = new JCheckBox("E"); Box box = Box.createVerticalBox(); box.add(label); box.add(a); box.add(b); box.add(c); box.add(d); box.add(e); JScrollPane jscrlpBox = new JScrollPane(box); jscrlpBox.setPreferredSize(new Dimension(140, 90)); f.add(jscrlpLabel); f.add(jscrlpBox); f.setVisible(true); }