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() 

Source Link

Document

Creates an initially unselected check box button with no text, no icon.

Usage

From source file:Main.java

public CheckComboRenderer() {
    checkBox = new JCheckBox();
}

From source file:com.moneydance.modules.features.importlist.table.AbstractEditor.java

protected AbstractEditor(final FileAdmin argFileAdmin, final ButtonRenderer argButtonRenderer) {
    super(new JCheckBox());
    Validate.notNull(argFileAdmin, "file admin must not be null"); //$NON-NLS-1$
    Validate.notNull(argButtonRenderer, "button renderer must not be null");
    this.fileAdmin = argFileAdmin;
    this.buttonRenderer = argButtonRenderer;
}

From source file:ExpenseReport.java

public ExpenseReport() {
    super("Expense Report");
    setSize(570, 200);/*w  ww  . j  a  va2  s .  com*/

    m_data = new ExpenseReportData(this);

    m_table = new JTable();
    m_table.setAutoCreateColumnsFromModel(false);
    m_table.setModel(m_data);
    m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    for (int k = 0; k < ExpenseReportData.m_columns.length; k++) {
        TableCellRenderer renderer;
        if (k == ExpenseReportData.COL_APPROVED)
            renderer = new CheckCellRenderer();
        else {
            DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer();
            textRenderer.setHorizontalAlignment(ExpenseReportData.m_columns[k].m_alignment);
            renderer = textRenderer;
        }

        TableCellEditor editor;

        if (k == ExpenseReportData.COL_CATEGORY)
            editor = new DefaultCellEditor(new JComboBox(ExpenseReportData.CATEGORIES));
        else if (k == ExpenseReportData.COL_APPROVED)
            editor = new DefaultCellEditor(new JCheckBox());
        else
            editor = new DefaultCellEditor(new JTextField());

        TableColumn column = new TableColumn(k, ExpenseReportData.m_columns[k].m_width, renderer, editor);
        m_table.addColumn(column);
    }

    JTableHeader header = m_table.getTableHeader();
    header.setUpdateTableInRealTime(false);

    JScrollPane ps = new JScrollPane();
    ps.setSize(550, 150);
    ps.getViewport().add(m_table);
    getContentPane().add(ps, BorderLayout.CENTER);

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    ImageIcon penny = new ImageIcon("penny.gif");
    m_title = new JLabel("Total: $", penny, JButton.LEFT);
    m_title.setForeground(Color.black);
    m_title.setAlignmentY(0.5f);
    p.add(m_title);
    p.add(Box.createHorizontalGlue());

    JButton bt = new JButton("Insert before");
    bt.setMnemonic('b');
    bt.setAlignmentY(0.5f);
    ActionListener lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = m_table.getSelectedRow();
            m_data.insert(row);
            m_table.tableChanged(
                    new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
            m_table.repaint();
        }
    };
    bt.addActionListener(lst);
    p.add(bt);

    bt = new JButton("Insert after");
    bt.setMnemonic('a');
    bt.setAlignmentY(0.5f);
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = m_table.getSelectedRow();
            m_data.insert(row + 1);
            m_table.tableChanged(new TableModelEvent(m_data, row + 1, row + 1, TableModelEvent.ALL_COLUMNS,
                    TableModelEvent.INSERT));
            m_table.repaint();
        }
    };
    bt.addActionListener(lst);
    p.add(bt);

    bt = new JButton("Delete row");
    bt.setMnemonic('d');
    bt.setAlignmentY(0.5f);
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = m_table.getSelectedRow();
            if (m_data.delete(row)) {
                m_table.tableChanged(new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS,
                        TableModelEvent.INSERT));
                m_table.repaint();
                calcTotal();
            }
        }
    };
    bt.addActionListener(lst);
    p.add(bt);

    getContentPane().add(p, BorderLayout.SOUTH);

    calcTotal();

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopCheckBox.java

public DesktopCheckBox() {
    impl = new JCheckBox();
    impl.addActionListener(e -> {
        updateInstance();
        fireChangeListeners(impl.isSelected());
    });
}

From source file:gdt.jgui.console.JItemPanel.java

/**
 * The constructor./*from  ww w  .j a  va2  s  .  c  o  m*/
 * @param console the main console.
 * @param locator$ the item's locator.
 */
public JItemPanel(JMainConsole console, String locator$) {
    this.console = console;
    this.locator$ = locator$;
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    setAlignmentX(Component.LEFT_ALIGNMENT);
    try {
        this.console = console;
        this.locator$ = locator$;
        Properties locator = Locator.toProperties(locator$);
        if (Locator.LOCATOR_TRUE.equals(locator.getProperty(Locator.LOCATOR_CHECKABLE))) {
            checkbox = new JCheckBox();
            add(checkbox);
            if (Locator.LOCATOR_TRUE.equals(locator.getProperty(Locator.LOCATOR_CHECKED)))
                if (checkbox != null)
                    checkbox.setSelected(true);
        }
        title$ = locator.getProperty(Locator.LOCATOR_TITLE);
        if (title$ != null) {
            title = new JLabel(title$, JLabel.LEFT);
            title.setText(title$);
            title.setOpaque(true);
            title.addMouseListener(new MousePopupListener());
            title.setAlignmentX(Component.LEFT_ALIGNMENT);
            add(title, BorderLayout.WEST);
            icon$ = locator.getProperty(Locator.LOCATOR_ICON);
            if (icon$ != null) {
                byte[] ba = Base64.decodeBase64(icon$);
                ImageIcon icon = new ImageIcon(ba);
                Image image = icon.getImage().getScaledInstance(24, 24, 0);
                icon.setImage(image);
                title.setIcon(icon);
            }
        } else
            LOGGER.info("title is null");

    } catch (Exception e) {
        LOGGER.severe(e.toString());

    }
}

From source file:biomine.bmvis2.pipeline.EdgeLabelOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = c.HORIZONTAL;//from  w ww . ja v a  2s .  co m
    c.weightx = 1;
    c.weighty = 0;
    c.gridy = 0;
    final Set<String> avail = graph.getAvailableEdgeLabels();

    for (final String str : avail) {
        final JCheckBox box = new JCheckBox();
        box.setSelected(enabledLabels.contains(str));
        box.setAction(new AbstractAction(str) {
            public void actionPerformed(ActionEvent arg0) {
                if (box.isSelected() != enabledLabels.contains(str)) {
                    if (box.isSelected())
                        enabledLabels.add(str);
                    else
                        enabledLabels.remove(str);
                    v.settingsChanged(false);
                }
            }
        });
        ret.add(box, c);
        c.gridy++;
    }

    return ret;
}

From source file:TabbedPaneTest.java

public TabbedPaneFrame() {
    setTitle("TabbedPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    tabbedPane = new JTabbedPane();
    // we set the components to null and delay their loading until the tab is shown
    // for the first time

    ImageIcon icon = new ImageIcon("yellow-ball.gif");

    tabbedPane.addTab("Mercury", icon, null);
    tabbedPane.addTab("Venus", icon, null);
    tabbedPane.addTab("Earth", icon, null);
    tabbedPane.addTab("Mars", icon, null);
    tabbedPane.addTab("Jupiter", icon, null);
    tabbedPane.addTab("Saturn", icon, null);
    tabbedPane.addTab("Uranus", icon, null);
    tabbedPane.addTab("Neptune", icon, null);
    tabbedPane.addTab("Pluto", null, null);

    final int plutoIndex = tabbedPane.indexOfTab("Pluto");
    JPanel plutoPanel = new JPanel();
    plutoPanel.add(new JLabel("Pluto", icon, SwingConstants.LEADING));
    JToggleButton plutoCheckBox = new JCheckBox();
    plutoCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tabbedPane.remove(plutoIndex);
        }/*from w ww  .j  a v a2  s.c om*/
    });
    plutoPanel.add(plutoCheckBox);
    tabbedPane.setTabComponentAt(plutoIndex, plutoPanel);

    add(tabbedPane, "Center");

    tabbedPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {

            // check if this tab still has a null component

            if (tabbedPane.getSelectedComponent() == null) {
                // set the component to the image icon

                int n = tabbedPane.getSelectedIndex();
                loadTab(n);
            }
        }
    });

    loadTab(0);

    JPanel buttonPanel = new JPanel();
    ButtonGroup buttonGroup = new ButtonGroup();
    JRadioButton wrapButton = new JRadioButton("Wrap tabs");
    wrapButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            tabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
        }
    });
    buttonPanel.add(wrapButton);
    buttonGroup.add(wrapButton);
    wrapButton.setSelected(true);
    JRadioButton scrollButton = new JRadioButton("Scroll tabs");
    scrollButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        }
    });
    buttonPanel.add(scrollButton);
    buttonGroup.add(scrollButton);
    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:com.stefanbrenner.droplet.utils.UiUtilsTest.java

@Test
public void testSetEnabledRecursive() {
    JPanel testPanel = new JPanel();

    JButton btnTest = new JButton();
    testPanel.add(btnTest);/* w  w  w .j av a 2 s.  c  o m*/
    JTextField txtTest = new JTextField();
    testPanel.add(txtTest);

    JPanel testPanel2 = new JPanel();
    JCheckBox chTest = new JCheckBox();
    testPanel2.add(chTest);

    testPanel.add(testPanel2);

    List<JComponent> allComps = Arrays
            .asList(new JComponent[] { testPanel, btnTest, txtTest, testPanel2, chTest });

    // disable all components
    UiUtils.setEnabledRecursive(testPanel, false);
    for (JComponent comp : allComps) {
        assertEquals(false, comp.isEnabled());
    }
    // re-enable all components
    UiUtils.setEnabledRecursive(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except txtTest
    UiUtils.setEnabledRecursive(testPanel, false, txtTest);
    for (JComponent comp : allComps) {
        if (ObjectUtils.notEqual(comp, txtTest)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabledRecursive(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except chTest in testPanel2
    UiUtils.setEnabledRecursive(testPanel, false, chTest);
    for (JComponent comp : allComps) {
        if (ObjectUtils.notEqual(comp, chTest)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabledRecursive(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except txtTest in testPanel and chTest in testPanel2
    JComponent[] except = new JComponent[] { txtTest, chTest };
    UiUtils.setEnabledRecursive(testPanel, false, except);
    for (JComponent comp : allComps) {
        if (!Arrays.asList(except).contains(comp)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabledRecursive(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

}

From source file:de.unidue.inf.is.ezdl.gframedl.components.checkboxlist.CheckBoxListCellRenderer.java

private void initialize() {
    panel = new JPanel();
    panel.setLayout(new BorderLayout());

    choicePanel = new JPanel(new BorderLayout());

    choice = new JCheckBox();

    choicePanel.add(choice, BorderLayout.CENTER);
    choicePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    choicePanel.setPreferredSize(new Dimension(150, 48));

    description = new JTextArea();
    description.setOpaque(true);//w w  w .  jav  a2s.  c o m
    description.setEditable(false);
    description.setLineWrap(true);
    description.setWrapStyleWord(true);

    description.setSize(400, 30);
    description.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    iconLabel = new JLabel();
    iconLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    choicePanel.add(iconLabel, BorderLayout.EAST);

    panel.add(choicePanel, BorderLayout.WEST);
    panel.add(description, BorderLayout.CENTER);

    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    panel.revalidate();
    panel.repaint();
}

From source file:EditorPaneTest.java

public EditorPaneFrame() {
    setTitle("EditorPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    final Stack<String> urlStack = new Stack<String>();
    final JEditorPane editorPane = new JEditorPane();
    final JTextField url = new JTextField(30);

    // set up hyperlink listener

    editorPane.setEditable(false);/*from w  ww. java  2 s . c  o  m*/
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    // remember URL for back button
                    urlStack.push(event.getURL().toString());
                    // show URL in text field
                    url.setText(event.getURL().toString());
                    editorPane.setPage(event.getURL());
                } catch (IOException e) {
                    editorPane.setText("Exception: " + e);
                }
            }
        }
    });

    // set up checkbox for toggling edit mode

    final JCheckBox editable = new JCheckBox();
    editable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            editorPane.setEditable(editable.isSelected());
        }
    });

    // set up load button for loading URL

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                // remember URL for back button
                urlStack.push(url.getText());
                editorPane.setPage(url.getText());
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    };

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(listener);
    url.addActionListener(listener);

    // set up back button and button action

    JButton backButton = new JButton("Back");
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (urlStack.size() <= 1)
                return;
            try {
                // get URL from back button
                urlStack.pop();
                // show URL in text field
                String urlString = urlStack.peek();
                url.setText(urlString);
                editorPane.setPage(urlString);
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    });

    add(new JScrollPane(editorPane), BorderLayout.CENTER);

    // put all control components in a panel

    JPanel panel = new JPanel();
    panel.add(new JLabel("URL"));
    panel.add(url);
    panel.add(loadButton);
    panel.add(backButton);
    panel.add(new JLabel("Editable"));
    panel.add(editable);

    add(panel, BorderLayout.SOUTH);
}