Java JTable Select createJCheckBoxForTable(boolean selected)

Here you can find the source of createJCheckBoxForTable(boolean selected)

Description

It creates a new check box for inclusion in a table and sets its "is selected" attribute to the given value.

License

Open Source License

Parameter

Parameter Description
selected It determines whether the newly-created check box will be selected or not.

Return

A new check box for inclusion in a table.

Declaration

static public JCheckBox createJCheckBoxForTable(boolean selected) 

Method Source Code


//package com.java2s;
/*/*from   www . j a  v  a  2  s .  com*/
 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 */

import java.awt.Color;

import javax.swing.JCheckBox;

import javax.swing.SwingConstants;

public class Main {
    /**
     * The foreground color for the table components.
     *
     * @see #createJLabelForTable()
     * @see #createJLabelForTable(String)
     * @see #createJCheckBoxForTable(boolean)
     */
    static final public Color TABLE_COMPONENT_FG_COLOR = Color.BLACK;
    /**
     * The background color for the table components.
     *
     * @see #createJLabelForTable()
     * @see #createJLabelForTable(String)
     * @see #createJCheckBoxForTable(boolean)
     */
    static final public Color TABLE_COMPONENT_BG_COLOR = Color.WHITE;

    /**
     * It creates a new check box for inclusion in a table and sets 
     * its "is selected" attribute to the given value.
     * 
     * @param selected It determines whether the newly-created check box
     * will be selected or not.
     * @return A new check box for inclusion in a table.
     */
    static public JCheckBox createJCheckBoxForTable(boolean selected) {
        JCheckBox checkBox = new JCheckBox();
        checkBox.setOpaque(true);
        checkBox.setHorizontalAlignment(SwingConstants.CENTER);
        checkBox.setForeground(TABLE_COMPONENT_FG_COLOR);
        checkBox.setBackground(TABLE_COMPONENT_BG_COLOR);
        checkBox.setSelected(selected);
        return checkBox;
    }
}

Related

  1. copyTableSelectionsToJList(JList list, JTable listTbl)
  2. disableSelection(JTable table)
  3. getSelectedCase(JTable table)
  4. getSelectedObject(JTable table)
  5. getSelectionBackground(JTable t)