List of usage examples for javax.swing JCheckBox JCheckBox
public JCheckBox(String text, Icon icon)
From source file:Main.java
public Main() { JCheckBox checkbox = new JCheckBox("Show Title", true); checkbox.addActionListener(this); add(checkbox);/* ww w .ja v a 2 s . c om*/ setSize(280, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:CheckBox.java
public CheckBox() { JCheckBox checkbox = new JCheckBox("Show Title", true); checkbox.addActionListener(this); add(checkbox);// ww w. j av a2s .c om setSize(280, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:Main.java
public Main() { // Add check boxes to the content pane. Icon normal = new MyIcon(Color.red); Icon rollover = new MyIcon(Color.YELLOW); Icon selected = new MyIcon(Color.BLUE); JCheckBox cb = new JCheckBox(normal, true); cb.setRolloverIcon(rollover);/*from www . j av a 2 s .c o m*/ cb.setSelectedIcon(selected); cb.addItemListener(this); add(cb); }
From source file:Main.java
public Main() { // Add check boxes to the content pane. Icon normal = new MyIcon(Color.red); Icon rollover = new MyIcon(Color.YELLOW); Icon selected = new MyIcon(Color.BLUE); JCheckBox cb = new JCheckBox("www.java2s.com", normal); cb.setRolloverIcon(rollover);/*from w w w . java 2s.c o m*/ cb.setSelectedIcon(selected); cb.addItemListener(this); add(cb); }
From source file:MainClass.java
public MainClass() { // Add check boxes to the content pane. Icon normal = new MyIcon(Color.red); Icon rollover = new MyIcon(Color.YELLOW); Icon selected = new MyIcon(Color.BLUE); JCheckBox cb = new JCheckBox("www.java2s.com", normal); cb.setRolloverIcon(rollover);/* ww w . j av a2 s.c o m*/ cb.setSelectedIcon(selected); cb.addItemListener(this); add(cb); }
From source file:MainClass.java
public MainClass() { super("Selection Model Test"); setSize(450, 350);/*from w ww . j av a2s . c om*/ setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { public int getRowCount() { return 10; } public int getColumnCount() { return 10; } public Object getValueAt(int r, int c) { return "0"; } }; final JTable jt = new JTable(tm); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); JPanel controlPanel, buttonPanel, columnPanel, rowPanel; buttonPanel = new JPanel(); final JCheckBox cellBox, columnBox, rowBox; cellBox = new JCheckBox("Cells", jt.getCellSelectionEnabled()); columnBox = new JCheckBox("Columns", jt.getColumnSelectionAllowed()); rowBox = new JCheckBox("Rows", jt.getRowSelectionAllowed()); cellBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setCellSelectionEnabled(cellBox.isSelected()); columnBox.setSelected(jt.getColumnSelectionAllowed()); rowBox.setSelected(jt.getRowSelectionAllowed()); } }); columnBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setColumnSelectionAllowed(columnBox.isSelected()); cellBox.setSelected(jt.getCellSelectionEnabled()); } }); rowBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setRowSelectionAllowed(rowBox.isSelected()); cellBox.setSelected(jt.getCellSelectionEnabled()); } }); buttonPanel.add(new JLabel("Selections allowed:")); buttonPanel.add(cellBox); buttonPanel.add(columnBox); buttonPanel.add(rowBox); columnPanel = new JPanel(); ListSelectionModel csm = jt.getColumnModel().getSelectionModel(); JLabel columnCounter = new JLabel("Selected Column Indices:"); csm.addListSelectionListener(new SelectionDebugger(columnCounter, csm)); columnPanel.add(new JLabel("Selected columns:")); columnPanel.add(columnCounter); rowPanel = new JPanel(); ListSelectionModel rsm = jt.getSelectionModel(); JLabel rowCounter = new JLabel("Selected Row Indices:"); rsm.addListSelectionListener(new SelectionDebugger(rowCounter, rsm)); rowPanel.add(new JLabel("Selected rows:")); rowPanel.add(rowCounter); controlPanel = new JPanel(new GridLayout(0, 1)); controlPanel.add(buttonPanel); controlPanel.add(columnPanel); controlPanel.add(rowPanel); getContentPane().add(controlPanel, BorderLayout.SOUTH); }
From source file:SysConfig.java
public SysConfig() { super("JTabbedPane & BoxLayout Demonstration"); setSize(500, 300);//from w w w . j av a 2 s . co m setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel configPane = new JPanel(); configPane.setLayout(new BoxLayout(configPane, BoxLayout.Y_AXIS)); JTextArea question = new JTextArea("Which of the following options\n" + "do you have installed?"); // Ok, now configure the textarea to show up properly inside the box. // This is part of the "high art" of Swing... question.setEditable(false); question.setMaximumSize(new Dimension(300, 50)); question.setAlignmentX(0.0f); question.setBackground(configPane.getBackground()); JCheckBox audioCB = new JCheckBox("Sound Card", true); JCheckBox nicCB = new JCheckBox("Ethernet Card", true); JCheckBox tvCB = new JCheckBox("Video Out", false); configPane.add(Box.createVerticalGlue()); configPane.add(question); configPane.add(audioCB); configPane.add(nicCB); configPane.add(tvCB); configPane.add(Box.createVerticalGlue()); JLabel audioPane = new JLabel("Audio stuff"); JLabel nicPane = new JLabel("Networking stuff"); JLabel tvPane = new JLabel("Video stuff"); JLabel helpPane = new JLabel("Help information"); audioCB.addItemListener(new TabManager(audioPane)); nicCB.addItemListener(new TabManager(nicPane)); tvCB.addItemListener(new TabManager(tvPane)); config.addTab("System", null, configPane, "Choose Installed Options"); config.addTab("Audio", null, audioPane, "Audio system configuration"); config.addTab("Networking", null, nicPane, "Networking configuration"); config.addTab("Video", null, tvPane, "Video system configuration"); config.addTab("Help", null, helpPane, "How Do I..."); getContentPane().add(config, BorderLayout.CENTER); }
From source file:SelectionExample.java
public SelectionExample() { super("Selection Model Test"); setSize(450, 350);//from w w w . j a v a2s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { // We'll create a simple multiplication table to serve as a // noneditable // table with several rows and columns public int getRowCount() { return 10; } public int getColumnCount() { return 10; } public Object getValueAt(int r, int c) { return "" + (r + 1) * (c + 1); } }; final JTable jt = new JTable(tm); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); // Now set up our selection controls JPanel controlPanel, buttonPanel, columnPanel, rowPanel; buttonPanel = new JPanel(); final JCheckBox cellBox, columnBox, rowBox; cellBox = new JCheckBox("Cells", jt.getCellSelectionEnabled()); columnBox = new JCheckBox("Columns", jt.getColumnSelectionAllowed()); rowBox = new JCheckBox("Rows", jt.getRowSelectionAllowed()); cellBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setCellSelectionEnabled(cellBox.isSelected()); columnBox.setSelected(jt.getColumnSelectionAllowed()); rowBox.setSelected(jt.getRowSelectionAllowed()); } }); columnBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setColumnSelectionAllowed(columnBox.isSelected()); cellBox.setSelected(jt.getCellSelectionEnabled()); } }); rowBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setRowSelectionAllowed(rowBox.isSelected()); cellBox.setSelected(jt.getCellSelectionEnabled()); } }); buttonPanel.add(new JLabel("Selections allowed:")); buttonPanel.add(cellBox); buttonPanel.add(columnBox); buttonPanel.add(rowBox); columnPanel = new JPanel(); ListSelectionModel csm = jt.getColumnModel().getSelectionModel(); JLabel columnCounter = new JLabel("(Selected Column Indices Go Here)"); csm.addListSelectionListener(new SelectionDebugger(columnCounter, csm)); columnPanel.add(new JLabel("Selected columns:")); columnPanel.add(columnCounter); rowPanel = new JPanel(); ListSelectionModel rsm = jt.getSelectionModel(); JLabel rowCounter = new JLabel("(Selected Row Indices Go Here)"); rsm.addListSelectionListener(new SelectionDebugger(rowCounter, rsm)); rowPanel.add(new JLabel("Selected rows:")); rowPanel.add(rowCounter); controlPanel = new JPanel(new GridLayout(0, 1)); controlPanel.add(buttonPanel); controlPanel.add(columnPanel); controlPanel.add(rowPanel); getContentPane().add(controlPanel, BorderLayout.SOUTH); }
From source file:de.codesourcery.eve.skills.ui.utils.PersistentDialog.java
public PersistentDialog(String id, Icon icon, String title, String label, PersistenceType type, Kind kind) { super(null, title, ModalityType.APPLICATION_MODAL); if (kind == null) { throw new IllegalArgumentException("kind cannot be NULL"); }/*from w w w . j a v a2 s . c o m*/ if (StringUtils.isBlank(id)) { throw new IllegalArgumentException("id cannot be blank."); } if (type == null) { throw new IllegalArgumentException("type cannot be NULL"); } if (StringUtils.isBlank(label)) { throw new IllegalArgumentException("label cannot be blank."); } this.id = id; this.type = type; // configure checkbox isDialogEnabled = new JCheckBox("Always show this dialog ?", true); isDialogEnabled.setHorizontalTextPosition(SwingConstants.RIGHT); // add panel final JPanel content = new JPanel(); content.setLayout(new GridBagLayout()); content.add(new JLabel(icon), new ConstraintsBuilder().x(0).y(0).anchorWest().noResizing().useRelativeWidth().end()); content.add(new JLabel(label), new ConstraintsBuilder().x(1).y(0).anchorWest().resizeBoth().useRemainingWidth().end()); content.add(isDialogEnabled, new ConstraintsBuilder().x(0).y(1).width(2).anchorWest().noResizing().end()); final JPanel buttonPanel = new JPanel(); buttonPanel.add(okButton); final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == cancelButton) { wasCancelled = true; } dispose(); } }; okButton.addActionListener(listener); if (kind == Kind.CANCEL) { buttonPanel.add(cancelButton); cancelButton.addActionListener(listener); } content.add(buttonPanel, new ConstraintsBuilder().x(0).y(2).useRemainingSpace().end()); getContentPane().add(content); pack(); setLocationRelativeTo(null); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { wasCancelled = true; dispose(); } }); }
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 w w w .ja v a 2 s. 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; }