Article View: aus.computers.java
Article #90Help to solve flickering Checkbox in JTable
From: Ben Munday
Date: Thu, 15 Jan 2004 04:14
Date: Thu, 15 Jan 2004 04:14
41 lines
2843 bytes
2843 bytes
Hi all,
I have a problem with a Checkbox in a JTable.
When i add the Checkbox into the JTable it displays the String
representation of the Checkbox, which is not what i want.
So, i created a CheckBoxRenderer which extens Checkbox and implements
TableCellRenderer. This seems to have done the job, in that the Checkbox
is displayed and not the String representation. But, and it's a big
'but', the column that holds the Checkbox continually updates the
fields. I cannot select the Checkbox and i can only just see that the
correct info for the Checkbox is in the cell.
I think it has something to do with repainting the Checkbox, but i can't
figure out how to stop it from happening.
Here is some of the code, the bit's i think are relevent:
All code is at:
http://www.users.on.net/benmunday/Label/
public class CheckBoxRenderer extends Checkbox implements TableCellRenderer
{
...
public Component getTableCellRendererComponent(JTable table, Object
cBox, boolean isSelected, boolean hasFocus, int row, int column)
{
Checkbox newCheckbox = (Checkbox)cBox;
newCheckbox.setState(false);
return newCheckbox;
}
}
JTable itemDataTable = new JTable(new MyTableModel(data));
itemDataTable.setDefaultRenderer(data[0][0].getClass(), new
CheckBoxRenderer());
itemDataScrollPane.getViewport().setView(itemDataTable);
itemDataScrollPane.setVisible(true);
contentPane.add(itemDataScrollPane, BorderLayout.CENTER);
Technical Details
Message-ID:
<400613be$1@duster.adelaide.on.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!news1.optus.net.au!optus!news.mel.connect.com.au!news.ade.connect.com.au!duster.adelaide.on.net!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113ae9,93a0ed3014c56a0,start X-Google-Attributes: gid113ae9,public X-Google-Thread: 10fd6d,93a0ed3014c56a0,start X-Google-Attributes: gid10fd6d,public X-Google-Thread: 10d6db,93a0ed3014c56a0,start X-Google-Attributes: gid10d6db,public X-Google-Thread: fecd1,93a0ed3014c56a0,start X-Google-Attributes: gidfecd1,public X-Google-ArrivalTime: 2004-01-14 20:14:55 PST Date: Thu, 15 Jan 2004 15:14:56 +1100 From: Ben Munday <benny111@hotmail.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: aus.computers.java,comp.lang.java.help,comp.lang.java.api,comp.lang.java.gui Subject: Help to solve flickering Checkbox in JTable Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: ppp126-160.lns1.syd3.internode.on.net Message-ID: <400613be$1@duster.adelaide.on.net> X-Trace: duster.adelaide.on.net 1074140094 ppp126-160.lns1.syd3.internode.on.net (15 Jan 2004 14:44:54 +1050) Lines: 42 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!news1.optus.net.au!optus!news.mel.connect.com.au!news.ade.connect.com.au!duster.adelaide.on.net!not-for-mail