List of usage examples for javax.swing JCheckBox setSelected
public void setSelected(boolean b)
From source file:Main.java
public static void main(String[] args) { JCheckBox a = new JCheckBox("A"); a.setSelected(true); JCheckBox b = new JCheckBox("B"); JCheckBox c = new JCheckBox("C"); JCheckBox d = new JCheckBox("D"); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Car Features")); frame.add(a);/*from w w w . j av a 2 s. c om*/ frame.add(b); frame.add(c); frame.add(d); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JCheckBox a = new JCheckBox("A"); a.setSelected(true); a.setMnemonic(KeyEvent.VK_A); JCheckBox b = new JCheckBox("B"); JCheckBox c = new JCheckBox("C"); JCheckBox d = new JCheckBox("D"); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Car Features")); frame.add(a);//from ww w .jav a 2 s . co m frame.add(b); frame.add(c); frame.add(d); frame.pack(); frame.setVisible(true); }
From source file:JCheckBoxTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JCheckBox Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox ac = new JCheckBox("A/C"); ac.setSelected(true); JCheckBox cdPlayer = new JCheckBox("A"); JCheckBox cruiseControl = new JCheckBox("B"); JCheckBox keylessEntry = new JCheckBox("C"); JCheckBox antiTheft = new JCheckBox("D"); JCheckBox centralLock = new JCheckBox("E"); frame.add(new JLabel("Car Features")); frame.add(ac);//from w w w . ja va 2s . c o m frame.add(cdPlayer); frame.add(cruiseControl); frame.add(keylessEntry); frame.add(antiTheft); frame.add(centralLock); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame result = new JFrame(); JComboBox<String> combobox = new JComboBox<>(new String[] { "foo", "bar", "aaa", "Hello World" }); result.add(combobox, BorderLayout.CENTER); JCheckBox toggleVisibility = new JCheckBox("Toggle visibility"); toggleVisibility.setSelected(combobox.isVisible()); toggleVisibility.addItemListener(e -> { combobox.setVisible(e.getStateChange() == ItemEvent.SELECTED); });/* ww w . j a va 2 s .co m*/ result.add(toggleVisibility, BorderLayout.SOUTH); result.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result.pack(); result.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JCheckBox checkbox = new JCheckBox(); // Get the current state of the checkbox boolean b = checkbox.isSelected(); // Set the state of the checkbox to off checkbox.setSelected(false); // Set the state of the checkbox to on checkbox.setSelected(true);// w w w .ja va2 s . co m }
From source file:EditorDropTarget2.java
public static void main(String[] args) { try {/*from www . j ava2 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 2"); final JEditorPane pane = new JEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget2 target = new EditorDropTarget2(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()); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); }
From source file:EditorDropTarget3.java
public static void main(String[] args) { try {/*from w w w .java 2 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:EditorDropTarget4.java
public static void main(String[] args) { try {// w w w. j a v a 2 s . com UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("JEditor Pane Drop Target Example 4"); // Create an editor with autoscrolling support final JEditorPane pane = new AutoScrollingEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget4 target = new EditorDropTarget4(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:DragDropTreeExample.java
public static void main(String[] args) { try {//from w w w. j a va 2 s . c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("FileTree Drop Target Example"); try { final FileTree tree = new FileTree("D:\\"); // Add a drop target to the FileTree FileTreeDropTarget target = new FileTreeDropTarget(tree); tree.setEditable(true); 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) { tree.setEditable(editable.isSelected()); } }); final JCheckBox enabled = new JCheckBox("Enabled"); enabled.setSelected(true); panel.add(enabled); enabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { tree.setEnabled(enabled.isSelected()); } }); f.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); } catch (Exception e) { System.out.println("Failed to build GUI: " + e); } }
From source file:DragDropTreeExample.java
public static void main(String[] args) { try {//from w ww. j a v a2s . co m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("FileTree Drop and Drop Example"); try { final FileTree tree = new FileTree("D:\\"); // Add a drop target to the FileTree FileTreeDropTarget target = new FileTreeDropTarget(tree); // Add a drag source to the FileTree FileTreeDragSource source = new FileTreeDragSource(tree); tree.setEditable(true); 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) { tree.setEditable(editable.isSelected()); } }); final JCheckBox enabled = new JCheckBox("Enabled"); enabled.setSelected(true); panel.add(enabled); enabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { tree.setEnabled(enabled.isSelected()); } }); f.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); } catch (Exception e) { System.out.println("Failed to build GUI: " + e); } }