Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 11:32 PM
Ben Munday
Guest
 
Posts: n/a
Default Help to solve flickering Checkbox in JTable

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.

Many thanx.
Ben

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(itemDataT able);
itemDataScrollPane.setVisible(true);

contentPane.add(itemDataScrollPane, BorderLayout.CENTER);

  #2  
Old July 17th, 2005, 11:32 PM
hiwa
Guest
 
Posts: n/a
Default Re: Help to solve flickering Checkbox in JTable

Ben Munday <benny111@hotmail.com> wrote in message news:<400613fd$1@duster.adelaide.on.net>...
[color=blue]
> http://www.users.on.net/benmunday/Label/[/color]
This URL is invalid.
[color=blue]
> public Component getTableCellRendererComponent(JTable table, Object
> cBox, boolean isSelected, boolean hasFocus, int row, int column)
> {
> Checkbox newCheckbox = (Checkbox)cBox;
> newCheckbox.setState(false);
> return newCheckbox;[/color]

I believe you better install conditionals upon isSelected and
hasFocus in the method. Another thing is that JComponent uses
double buffering by default so I believe you should use JCheckBox
instead of awt.CheckBox. In general, mixing use of the awt
component and Swing component is not a good, let alone best,
practice.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.