COMBOBOX & CHECKBOX RENDERER IN JTABLE

Hi,
I created JXTable by using swingx palette in Netbeans IDE. In two columns of my table, for each row I want to put checkboxes and comboboxes. I searched the ways on internet and I finalise my code. However, because I used cell editor, I just see my checkboxes and comboboxes when I enter a specific cell. I read all tutorials but unfortunately I cannot learn how to use renderer to show comboboxes and checkboxes all the time. In below you could check my code and if possible please teach how to use renderers and try to give feedback to my code by fixing it. Thank you.
*(P.S Please don't send any web site for tutorial, i searched almost all of them; but I can't understand the logic of it.)*
// SET UP THE COMBO BOX
public void setUpOverwriteValueColumn(JXTable table, TableColumn overwriteValCol) {
valueCombo = new JComboBox();
Field field = new Field();
ArrayList values = new ArrayList();
values = field.getValues();
for(String a:values){
valueCombo.addItem(a);
overwriteValCol.setCellEditor(new DefaultCellEditor(valueCombo));
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
overwriteValCol.setCellRenderer(renderer);
// SET UP THE CHECK BOX
public void setUpOverwriteColumn(JXTable table, TableColumn overwriteCol) {
valueChk = new JCheckBox();
overwriteCol.setCellEditor(new DefaultCellEditor(valueChk));
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for check box");
overwriteCol.setCellRenderer(renderer);
setUpOverwriteColumn(monitorTable, monitorTable.getColumnModel().getColumn(3)); //add checkbox to 3rd column
setUpOverwriteValueColumn(monitorTable, monitorTable.getColumnModel().getColumn(4)); //add combobox to 4th column

Finally I can add renderers. But, now I have different question. When user clicks on the checkbox I want to enable the combo box. I mean if user clicks the checkbox in row 3; only the combo box which placed in row 3 should be enabled; other combos in other rows should not be enabled. Please help if you know the answer. Here is my code:
public class ComboBoxRenderer extends JComboBox implements TableCellRenderer{
    public ComboBoxRenderer(Vector items) {
        super(items);
        setOpaque(false);
    public Component getTableCellRendererComponent(
                                                JTable table,
                                                Object value,
                                                boolean isSelected,
                                                boolean hasFocus,
                                                int row,
                                                int column){
        if (isSelected && !hasFocus){
            setBackground(table.getSelectionBackground());
            setForeground(table.getSelectionForeground());
        }else{
            setBackground(table.getBackground());
            setForeground(table.getForeground());
          setSelectedItem(value);
        return this;
public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer
  public CheckBoxRenderer() {
    setOpaque(false);
    setHorizontalAlignment(CENTER);
    setVerticalAlignment(CENTER);
  public Component getTableCellRendererComponent(
                                                    JTable table,
                                                    Object value,
                                                    boolean isSelected,
                                                    boolean hasFocus,
                                                    int row,
                                                    int column) {
    if (value != null) {
      this.setSelected( ( (Boolean) value).booleanValue());
    return this;
}To show:
public void setUpOverwriteValueColumn(JXTable table,
                                 TableColumn overwriteValCol) {
        Vector v = new Vector();
        Field field = new Field();
            ArrayList <String> values = new ArrayList<String>();
            values = field.getValues();
            for(String a:values){
                v.addElement(a);
            ComboBoxRenderer renderer = new ComboBoxRenderer(v);
            overwriteValCol.setCellRenderer(renderer);
    // SET UP THE CHECK BOX
    public void setUpOverwriteColumn(JXTable table, TableColumn overwriteCol) {
            CheckBoxRenderer renderer = new CheckBoxRenderer();
            overwriteCol.setCellRenderer(renderer);
    }Edited by: duygu_simsek on Jun 18, 2009 11:27 AM

Similar Messages

  • Cell rendering in JTable

    Can someone show me how to render the cells of a table column as a combo box and the cells of another table column as a check box.
    thx.

    Hi,
    You can easily get the checkbox as the renderer by implementing the getColumnClass(int columnIndex). But the catch is that your checkbox-column should return Boolean as its class. Check for that. That can only be the problem. Otherwise, it should work fine.
    public Class getColumnClass(int column) {
        switch(column) {
            case 1 :
                /* Assume that this is the column for which the checkbox
                 * rendering has to take place.
                return Boolean.class;
                break;
            case 2 :
                //Return the datatype of this column, say it is a Number
                return Number.class;
                break;
            //Your other cases would go here
            default :
                return String.class;
                break;
    }I hope that your problem is solved now. If not, there is another way by which you can explicitlt set the renderer of your column. In this case, there is no need to implement the getColumnClass() method. Here is the CheckBoxCellRender class...
    class CheckBoxCellRenderer extends JCheckBox implements TableCellRenderer
        public CheckBoxCellRenderer() {
            setHorizontalAlignment(JLabel.CENTER);
        }//constructor
        public Component getTableCellRendererComponent(JTable table, Object value,
                               boolean isSelected, boolean hasFocus, int row, int column) {
        if (isSelected) {
            setForeground(table.getSelectionForeground());
            super.setBackground(table.getSelectionBackground());
        else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
            setSelected((value != null && ((Boolean)value).booleanValue()));
            return this;
        }//getTableCellRendererComponent
    }Put this class as an inner class somewhere in your code, and then explicitly set this class as the column's default renderer. Here is how you can do it.
    myTable.getColumn("myCheckboxColumn").setCellRenderer(new CheckBoxCellRenderer());

  • Help required for creating Row Renderer for JTable

    Hi all,
    I am trying to create customize row renderer for JTable.
    My requirements are as below.
    |-----------------|-------------------|------------------|------------------|-------|----------------|
    |Category | Product ID |Description | Unit Price |Qty | Sub-Total |
    |-----------------|-------------------|------------------|------------------|-------|----------------|
    I have designed a combobox for category and product ID columns inside JTable. I want to put a listener on Category ID such that product IDs in selected categories will be visible in product ID drop down of selected row keeping other rows unchanged.
    Column renderer is defining a class for entire column but by setting that im getting same values in all the rows for product IDs. And if I update values for one product ID dropdown, entire column data is changing.
    Even im not able to put array of combobox for product ID column as number of rows are not fixed and increasing runtime.
    Can anyone suggest me how can i customize Cells under particular column with JComboBox?
    Regards,
    Mahesh Kedari
    Fidus Technologies Ltd.
    Edited by: m1JustM1 on Feb 8, 2010 4:48 AM

    Start by reading [this |http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender] tutorial. If you still have questions afterward, feel free to post an SSCCE .

  • Exception -arrayindexoutobound  while inserting checkbox in a jtable

    hello,
    i am using oracle as backend. As you might be knowing that oracle doesn't store boolean datatype.
    so now please tell me how to insert checkbox in a jtable.
    please do help me if you can.

    HELLO camickr
    ONE INTERESTING THING IS HAPPENING->
    i had created 2 table in my form 1) jtable1 2) jtable2
    i had declared the listener on JTABLE1 as->
    jTable1.addMouseListener(new Mousehandler())
    I HAD WRITTEN THE METHOD AS->
    public class Mousehandler extends MouseAdapter
    public void mouseClicked(MouseEvent me)
    //NOTE ->HERE IS THE CODE TO ADD CHECKBOX ON A COLUMN FOR JTABLE1
    TableColumn sport= jTable1.getColumnModel().getColumn(1);
    // str=jTable1.getCellEditor();
    JCheckBox jCheckBox1 = new JCheckBox();
    sport.setCellEditor(new DefaultCellEditor(jCheckBox1));
    //NOTE-> HERE IS THE CODE TO ADD JCHECKBOX ON A JTABLE2
    TableColumn sportcol = jTable2.getColumnModel().getColumn(1);
    JCheckBox jCheckBox2 = new JCheckBox();
    sportcol.setCellEditor(new DefaultCellEditor(jCheckBox2));
    now when i click on JTABLE1 IT IS THROWING EXCEPTION BUT WHEN FUNCTIONING WITH jTable2 WHEN I CLICK ON THE COLUMN IN WHICH I HAD INSERTED CHECKBOX IT IS FUNCTIONING PROPERLY WITHOUT ANY ERROR.
    NOTE-> I HAD TO CLICK ONCE ON JTABLE1 THEN ONLY JTABLE2
    FUNCTION BECAUSE I HAD DECLARED LISTENER FOR JTABLE1 ONLY.(JTABLE1 IS THROWING AN EXCEPTION ARRAYINDEXOUTOFBOUND when i click on the column in which i had inserted jcheckbox im my jtable1)
    PLEASE DO HELP ME IF YOU CAN.
    THANK YOU.

  • Problem : Not able to select multiple checkboxes in the JTable

    Here i am trying to select the multiple check boxes in the jtable. But i am not able to do that. I set the jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); also.
    Can any one help on this...

    [email protected] wrote:
    Here i am trying to select the multiple check boxes in the jtable. But i am not able to do that. I set the jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); also.
    Can any one help on this...That's row selection, not check boxes. The normal way to have active checkboxes in a JTable is with an editable Boolean column. The effect of clicking such a checkbox is to cause the table to call setValueAt() in the data model with a Boolean object value, and it's up to the data model to deal with that change.

  • Datagrid checkbox renderer refresh?

    I am using a checkbox renderer for one of the columns in a
    flex datagrid.
    When i scroll up or down, the checkboxes i have alread
    clicked, change to different boxes (records). ????
    Not sure if this is a redraw issue. Tried to validate, but
    did not help.
    Please help.

    When we add a customized checkbox column to a datagrid in .net (windows application) , the default property allows to check or uncheck the column using a double click. On the first click it selects the column and on the second click the column is either checked or unchecked.
    To change this default property, we need to handle the click event on grid and modify the selected cell value. Here is the sample code to achieve this.
    [C#.NET VS 2003 , Code to add checkbox column to grid using table style property]
    dgItemDetails.TableStyles.Clear(); // clears the tablestyle (dgItemDetails is the name of grid)
    DataGridTableStyle dgt = new DataGridTableStyle();
    dgt.MappingName = "ItemDetails";
    DataGridBoolColumn dgbCol = new DataGridBoolColumn(); // creates the checkbox column
    dgbCol.MappingName = "Select";
    dgbCol.HeaderText = "";
    dgbCol.Width = 40;
    dgbCol.AllowNull = false;
    dgbCol.Alignment = HorizontalAlignment.Left;
    dgt.GridColumnStyles.Add(dgbCol);
    dgItemDetails.TableStyles.Add(dgt); // add
    Eliza

  • Align for multi-header renderer in JTable

    Hi,
    I have a question about multi-header renderer in JTable. Here is the problem, please help me:
    I used the MultiLineHeaderRenderer class example from
    http://www2.gol.com/users/tame/swing/examples/JTableExamples1.html
    This example makes the header to be centered (as setHorizontalAlignment(JLabel.CENTER)). Also, it is for the all the headers with 2 lines (i don't know how to describe it).
    In my project, I have just a few header with 2 lines, most of them are one line. By using this example renderer class, I have the header height is bigger, of course because of some 2 lines headers, and one line header is automatically set as the TOP. What I want is to make one line header to be set as the BOTTOM just like in EXCEL.
    Please help me, sorry for my technical explaination (poor huh?)
    Thanks in advance.

    If I understand correctly just put a space then a new line before your text for your cell that you want the text at the bottom.
    like this: " \nBottom Text"
    You'll need the leading space because of how StringTokenizer works.

  • Check a checkbox in a jtable in a panel from another panel

    I have a panel-> Panel A
    where I have some conditions and on that condition I want to check a checkbox in a jtable in another panel ->PanelB
    So Panel B has a jtable with one column as checkbox,I want to check/uncheck this checkbox based on some conditions in some other panel A
    I have no idea how to do this.Please help.
    Thanks

    885522 wrote:
    How will the change be reflected dynamically if the value changes in some other panel.By code that you write. If you want component X to change based on some changes to component Y, then first you set up a listener which will notify you when changes to component Y take place. In that listener you put code which makes the appropriate changes to component X, based on what happened to component Y.

  • Checkbox renderer problem

    Hi all,
    I have a checkbox renderer in datagrid .The dataprovider does
    not have the selected property of the checkbox.
    how do i retain the selection of the checkbox,when i scroll
    the datagrid?
    please help.
    Thanks

    thank u very much..
    in set data method,i added the following
    override public function set data(value:Object):void{
    if(value != null){
    super.data = value;
    if((data.chkselected==null) ||
    (data.chkselected=="undefined")){
    data.chkselected = false;
    this.selected = data.chkselected;
    this works when i change checkbox selection in each row..
    i have another problem..can u please help me in solving this
    i have a checkbox as header renderer..
    On click, it is selectiing/deselecting only the checkboxes of
    rows which are visible and when i scroll the datagrid,other
    checkboxes are not selected/deselected
    thanks

  • Refreshing renderer in jtable

    hi all,
    i am using JLabel for rendering a JTable, but the problem is
    JTable is not refreshing properly.
    import java.awt.Component;
    import java.awt.Container;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.TableCellRenderer;
    public class SampleTable extends JFrame
        public SampleTable()
            Container container = getContentPane();
            container.add(getHtmlTable());
            setSize(400, 400);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        private JScrollPane getHtmlTable()
            Object[] tblColHeaders = {"a","b"};
            Object[][] tradedata = {
                    {"<HTML><table >"
                     + "<tr><td >row 1, cell 1</td></tr></table></HTML>", "<HTML><table>"
                           + "<tr><td>row 1, cell 1</td></tr><tr><td>row 1, cell 2</td></tr></tr><tr><td>row 1, cell 2</td></tr>"
                           + "</table></HTML>"},
                    { "<HTML><table >"
                     + "<tr><td >row 1, cell 1</td></tr>"
                     + "</table></HTML>", "<HTML><table>"
                           + "<tr><td>row 1, cell 1</td></tr><tr><td>row 1, cell 2</td></tr></tr><tr><td>row 1, cell 2</td></tr>"
                           + "</table></HTML>"},
                    { "<HTML><table >"
                     + "<tr><td >row 1, cell 1</td></tr>"
                     + "</table></HTML>", "<HTML><table>"
                           + "<tr><td>row 1, cell 1</td>/tr><tr><td>row 1, cell 2</td></tr></tr><tr><td>row 1, cell 2</td></tr>"
                           + "</table></HTML>"}};
            JTable table = new JTable(tradedata,tblColHeaders){
                public boolean isCellEditable(int row,int col){
                    return false;
            table.setDefaultRenderer(Object.class,new MyTableCellRenderer());
            JScrollPane scrTabel = new JScrollPane(table);
            return scrTabel;
        public class MyTableCellRenderer extends JLabel implements TableCellRenderer
            public Component getTableCellRendererComponent(JTable table, Object value,
                                                           boolean isSelected, boolean hasFocus,
                                                           int rowIndex, int vColIndex)
                setText(value.toString());
                setSize(table.getColumnModel().getColumn(vColIndex).getWidth(),
                        getPreferredSize().height);
                if (table.getRowHeight(rowIndex) != getPreferredSize().height)
                    table.setRowHeight(rowIndex, getPreferredSize().height);
                if(isSelected){
                    setBackground(table.getSelectionBackground());
                    setForeground(table.getSelectionForeground());
                return this;
        public static void main(String[] args)
            new SampleTable();
    }thanks
    daya

    1) Your renderer is in an infinite loop because column one need a row height of 16, so you change the height, but column two need a row height of 48, so you change the height.
    But whenever you change the row height the table needs to render the entire row, so it tries to render column 1 again and it resets the height, then column 2 and it resets the height etc, etc.
    2) All you want you renderer to do is change the height, so don't create the renderer from scratch. That is don't extend JLabel, extend DefaultTableCellRenderer so you don't need to add all the custom code.
    Your renderer should be something like this:
        public class MyTableCellRenderer extends DefaultTableCellRenderer
            public Component getTableCellRendererComponent(JTable table, Object value,
                                                           boolean isSelected, boolean hasFocus,
                                                           int rowIndex, int vColIndex)
                super.getTableCellRendererComponent(table,
                    value, isSelected, hasFocus, rowIndex, vColIndex);
                if (table.getRowHeight(rowIndex) < getPreferredSize().height)
                    table.setRowHeight(rowIndex, getPreferredSize().height);
                return this;
        }

  • When the combobox is rendered all the values displayed look like [object Object].

    I wasn't sure where to post this so please forgive me.
    I am trying to populate a combobox with a series of values
    returned from a Coldfusion method that retrives a resault froma
    database. Basically all the data from a table of staff.
    <cffunction name="getUsers" access="remote"
    returntype="array">
    <cfquery name="q" datasource="#datasource#">
    SELECT *
    FROM STAFF_CHARTS_STAFF_TEMP
    </cfquery>
    <cfset aRecordset= querytoarray(q)>
    <cfset flash.result=aRecordset>
    <cfreturn flash.result>
    </cffunction>
    <cffunction name="querytoarray" returntype="array"
    output="No">
    <cfargument name="q" required="Yes" type="query">
    <cfset var aTmp = arraynew(1)>
    <cfif q.recordcount>
    <cfloop query="q">
    <cfset stTmp = structNew()>
    <cfloop list="#lcase(q.columnlist)#" index="col">
    <cfset stTmp[col] = q[col][currentRow]>
    </cfloop>
    <cfset arrayAppend(aTmp,stTmp)>
    </cfloop>
    <cfelse>
    <cfset stTmp = structNew()>
    <cfloop list="#lcase(q.columnlist)#" index="col">
    <cfset stTmp[col] = "">
    </cfloop>
    <cfset arrayAppend(aTmp,stTmp)>
    </cfif>
    <cfreturn aTmp>
    </cffunction>
    The result from a call of CF method getUsers is set as the
    data provider to ComboBox with id = "cb"
    <mx:RemoteObject
    id="myService"
    destination="ColdFusion"
    source="staff_ratings.staff_Ratings-debug.staff"
    showBusyCursor="true">
    <mx:method name="getUsers" result="handleResult(event)"
    fault="Alert.show(event.fault.message)"/>
    </mx:RemoteObject>
    <mx:Script>
    <![CDATA[
    import mx.rpc.events.ResultEvent;
    import mx.controls.Alert;
    [Bindable]
    public var sResult:Array;
    public function handleResult(event:ResultEvent):void{
    sResult=event.result as Array;
    cb.dataProvider=sResult;
    ]]>
    </mx:Script>
    However when the combobox is rendered all the values
    displayed look like [object Object].
    I think the problem is that the result is a array of arrays
    so I need to find away to ectract a particular colun of data into
    the combobox
    How do I fix this?

    This is what I did for a single field.
    If you were wanting the to have muliple fields in the
    dropdown, I would concatenate them in the query.
    something like
    select fname + ' ' + lname + ' ' + anotherfield as tech from
    dbo.table
    <cffunction name="getTech" output="no" access="remote"
    returntype="query">
    <cfset var qTech="">
    <cfquery name="qTech" datasource="datasource">
    select tech
    from dbo.table
    group by tech
    order by tech
    </cfquery>
    <cfreturn qTech>
    </cffunction>
    <mx:RemoteObject
    id="dataManager"
    showBusyCursor="true"
    destination="ColdFusion"
    source="cust.components.cfgenerated.Records">
    <mx:method name="getMasterQuery"
    result="getMasterQuery_result(event)" fault="server_fault(event)"
    />
    <mx:method name="deleteItem"
    result="deleteItem_result(event)" fault="server_fault(event)" />
    </mx:RemoteObject>
    <mx:ComboBox id="TECH"
    dataProvider="{dataManager.getTech.lastResult}" labelField="tech"
    />

  • Combobox Renderer in JTable

    Can someone please post code showing me how to make a renderer that would indicate a combobox in a JTable? I already have the combobox editor there, but I want the renderer to show a small down arrow, indicating to the user that the cell is a combobox.
    Thanks!

    public class ComboBoxRenderer extends JComboBox implements TableCellRenderer{
        public ComboBoxRenderer(Vector items) {
            super(items);
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
            if (isSelected && !hasFocus){
                setBackground(table.getSelectionBackground());
                setForeground(table.getSelectionForeground());
            }else{
                setBackground(table.getBackground());
                setForeground(table.getForeground());
            setSelectedItem(value);
            return this;
    [/code[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Unable to check / uncheck a checkbox in a JTable...

    Hi all,
    I know that a lot of people have asked this question before but I am unable to find a solution even after going all the messages. My issue is:
    My initial rendering of the checkboxes inside the table works ok. I am using a TableCellRenderer and my input to determine the "checked/unchecked" is string like "true" or "false" and not boolean values. But I am unable to do check / uncheck any of the checkboxes.
    I would really appreciate any pointers.
    Thanks in advance.
    Below is my code snippet:
    public Component getTableCellRendererComponent(JTable table_,
    Object value_, boolean isSelected_, boolean hasFocus_, int rowIndex_,
    int colIndex_)
    Component component = super.getTableCellRendererComponent(table_,
    value_, isSelected_, hasFocus_, rowIndex_, colIndex_);
    indicator = table_.getColumnModel().getColumnIndex("IND");      
    if (indicator == colIndex_)
         if (value_.equals("true")){
              component = new JCheckBox("", true);           
         } else {
              component = new JCheckBox("", false);           
         return component;
    }

    Your TableModel has to indicate that the column is editable. Your TableModel also has to implement setValueAt() so that when the user changes the value, it updates the data.
    The table will know to use it's own boolean renderer/editor for that column because it knows what to do when a column returns a Boolean.

  • How can I change the foregroud of checkboxes in a JTable ?

    Hello!
    I develop an application module to let a user correcting a list of pre-filled forms.
    I extended JTable with customized model, cell renderer and cell editor.
    A form can be disabled. All elements are then disabled as my tables.
    I encountered a minor GUI problem on JTable: I do not find a solution to let checkboxes displayed as disabled, even if checkboxes are effectively user disabled ( when i did myTable.setEnabled(false) ).
    Do you know a way to change the foreground color of the checkboxes in my tables?
    Thanks
    HugO

    It's ok, I've just found the solution.
    Simply, in method
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column), of class MyCheckBoxCellRenderer (extending JCheckBox), I need to add the only line setEnabled(table.isEnabled()).
    Sorry for that!

  • How to set cell background color for JCheckBox renderer in JTable?

    I need to display table one row with white color and another row with customized color.
    But Boolean column cannot set color background color.
    Here is my codes.
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.TreeSet;
    public class BooleanTable extends JFrame
        Object[][] data = {{Boolean.TRUE},{Boolean.TRUE},{Boolean.TRUE},{Boolean.TRUE},{Boolean.TRUE},{Boolean.TRUE}};
        String[] header = {"CheckBoxes"};
        public BooleanTable()
            setDefaultCloseOperation( EXIT_ON_CLOSE );
            TableModel model = new AbstractTableModel()
                public String getColumnName(int column)
                    return header[column].toString();
                public int getRowCount()
                    return data.length;
                public int getColumnCount()
                    return header.length;
                public Class getColumnClass(int columnIndex)
                    return( data[0][columnIndex].getClass() );
                public Object getValueAt(int row, int col)
                    return data[row][col];
                public boolean isCellEditable(int row, int column)
                    return true;
                public void setValueAt(Object value, int row, int col)
                    data[row][col] = value;
                    fireTableCellUpdated(row, col);
            JTable table = new JTable(model);
            table.setDefaultRenderer( Boolean.class, new MyCellRenderer() );
            getContentPane().add( new JScrollPane( table ) );
            pack();
            setLocationRelativeTo( null );
            setVisible( true );
        public static void main( String[] a )
            try
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            catch( Exception e )
            new BooleanTable();
        private class MyCellRenderer extends JCheckBox implements TableCellRenderer
            public MyCellRenderer()
                super();
                setHorizontalAlignment(SwingConstants.CENTER);
            public Component getTableCellRendererComponent(JTable
                                                           table, Object value, boolean isSelected, boolean
                                                           hasFocus, int row, int column)
                if (isSelected) {
                   setForeground(Color.white);
                   setBackground(Color.black);
                } else {
                   setForeground(Color.black);
                   if (row % 2 == 0) {
                      setBackground(Color.white);
                   } else {
                      setBackground(new Color(239, 245, 217));
                setSelected( Boolean.valueOf( value.toString() ).booleanValue() );
             return this;
    }

    Instead of extending JCheckBox, extend JPanel... put a checkbox in it. (border layout center).
    Or better yet, don't extend any gui component. This keeps things very clean. Don't extend a gui component unless you have no other choice.
    private class MyCellRenderer implements TableCellRenderer {
        private JPanel    _panel = null;
        private JCheckBox _checkBox = null;
        public MyCellRenderer() {
            //  Create & configure the gui components we need
            _panel = new JPanel( new BorderLayout() );
            _checkBox = new JCheckBox();
            _checkBox.setHorizontalAlignment( SwingConstants.CENTER );
            // Layout the gui
            _panel.add( _checkBox, BorderLayout.CENTER );
        public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
            if( isSelected ) {
               _checkBox.setForeground(Color.white);
               _panel.setBackground(Color.black);
            } else {
               _checkBox.setForeground(Color.black);
               if( row % 2 == 0 ) {
                  _panel.setBackground(Color.white);
               } else {
                  _panel.setBackground(new Color(239, 245, 217));
            _checkBox.setSelected( Boolean.valueOf( value.toString() ).booleanValue() );
            return _panel;
    }

Maybe you are looking for

  • Exchange 2010, Outlook 2010, Outlook 2011 (Mac)

    Hey Team I am working on an issue with "Send on Behalf of", the permissions have been granted and it is working, however the user wants to be able to do the following: (And only the following) 1) Click on the Inbox of her manager (In outlook), She ha

  • Crystal Reports Server vs BOEXI3.1

    We currently have BOEXI3.1 I am trying to figure out a solution that would allow an Asp.net front end to display my crystal reports. What is the difference between Crystal Reports Server and what I have? It would seem that with what I have now I am g

  • How to change table name after creating page and application

    Hi HTMLDB Team, i have created a application with page where the region use master detail form with table name emp.Now after developing the page and the application i want to change the table from emp to emp2 where emp2 is the table with same structu

  • Problem with macbook pro trackpad

    The bottom right part of the trackpad feels really weak, when i push it down it goes really deep i really dont know how this happened. Can you help please.

  • ADMT share domain local groups access denied

    Hi,  I have encountered strange behavior when migrating share with permissions. This is the situation: 1) We have migrated groups from source domain(these groups are used for defining access to shares, users are directly members of these, no nested g