Thread View: aus.computers.java
8 messages
8 total messages
Started by Ben Munday
Thu, 15 Jan 2004 04:14
Help to solve flickering Checkbox in JTable
Author: 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);
Re: Help to solve flickering Checkbox in JTable
Author: ak
Date: Thu, 15 Jan 2004 04:53
Date: Thu, 15 Jan 2004 04:53
21 lines
1973 bytes
1973 bytes
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.
> public Component getTableCellRendererComponent(JTable table, Object
> cBox, boolean isSelected, boolean hasFocus, int row, int column)
> {
> Checkbox newCheckbox = (Checkbox)cBox;
> newCheckbox.setState(false);
> return newCheckbox;
> }
lol, its because you call setState(false) from
getTableCellRendererComponent();
throw newCheckbox.setState(false); away then everything work.
--
____________
http://reader.imagero.com the best java image reader.
Re: Help to solve flickering Checkbox in JTable
Author: Ben Munday
Date: Thu, 15 Jan 2004 06:03
Date: Thu, 15 Jan 2004 06:03
37 lines
2337 bytes
2337 bytes
I commented out the section you suggested, but the flicker was still
there. what i have in that method now is:
public Component getTableCellRendererComponent(JTable table, Object
cBox, boolean isSelected, boolean hasFocus, int row, int column)
{
Checkbox newCheckbox = (Checkbox)cBox;
return newCheckbox;
}
ak wrote:
> 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.
>
>
>> public Component getTableCellRendererComponent(JTable table, Object
>>cBox, boolean isSelected, boolean hasFocus, int row, int column)
>> {
>> Checkbox newCheckbox = (Checkbox)cBox;
>> newCheckbox.setState(false);
>> return newCheckbox;
>> }
>
>
> lol, its because you call setState(false) from
> getTableCellRendererComponent();
>
> throw newCheckbox.setState(false); away then everything work.
> --
>
> ____________
>
> http://reader.imagero.com the best java image reader.
>
>
Re: Help to solve flickering Checkbox in JTable
Author: Ben Munday
Date: Thu, 15 Jan 2004 06:46
Date: Thu, 15 Jan 2004 06:46
41 lines
2413 bytes
2413 bytes
The solution was to change all the references to Class Checkbox to Class
JCheckBox.
Firstly, i appreciate your willingness to answer a question in comunity
newsgroups.
Secondly, if you are going to present you answers as correct, make sure
they are. Did you make the changes in the code and then test it? Or did
you think that you had the right answer so you didn't bother to make
sure.....
Ben
ak wrote:
> 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.
>
>
>> public Component getTableCellRendererComponent(JTable table, Object
>>cBox, boolean isSelected, boolean hasFocus, int row, int column)
>> {
>> Checkbox newCheckbox = (Checkbox)cBox;
>> newCheckbox.setState(false);
>> return newCheckbox;
>> }
>
>
> lol, its because you call setState(false) from
> getTableCellRendererComponent();
>
> throw newCheckbox.setState(false); away then everything work.
> --
>
> ____________
>
> http://reader.imagero.com the best java image reader.
>
>
Re: Help to solve flickering Checkbox in JTable
Author: Andrew Thompson
Date: Thu, 15 Jan 2004 11:21
Date: Thu, 15 Jan 2004 11:21
29 lines
2205 bytes
2205 bytes
"Ben Munday" <benny111@hotmail.com> wrote in message news:4006373c$1@duster.adelaide.on.net... |...if you are going to present you answers as correct, make sure | they are. That's rich! You come in here posting code snippets (useless), then want to complain about the advice you get from ak! Next time, post an SSCCE and you might get better answers. http://www.physci.org/codes/sscce.jsp |..Did you make the changes in the code and then test it? That was impossible, given your post. If you do not like the answers you are getting off this group, then.. a) Demand a full refund, and.. b) Ensure the door does not smack in the ass on the way out.. -- Andrew Thompson * http://www.PhySci.org/ PhySci software suite * http://www.1point1C.org/ 1.1C - Superluminal! * http://www.AThompson.info/andrew/ personal site
Re: Help to solve flickering Checkbox in JTable
Author: NetExplorer
Date: Sun, 29 Feb 2004 08:49
Date: Sun, 29 Feb 2004 08:49
88 lines
5157 bytes
5157 bytes
I'll just address the first part of your code. Are you truly using a
Checkbox from AWT within a JTable? Don't mix awt and swing components if you
can help it.
Read up in the Java Tutorial (on sun's site) and study the java api for the
TableCellRenderer interface:
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)Returns the
component used for drawing the cell. This method is used to configure the
renderer appropriately before drawing.
Parameters:
table - the JTable that is asking the renderer to draw; can be null
value - the value of the cell to be rendered. It is up to the specific
renderer to interpret and draw the value. For example, if value is the
string "true", it could be rendered as a string or it could be rendered as a
check box that is checked. null is a valid value
isSelected - true if the cell is to be rendered with the selection
highlighted; otherwise false
hasFocus - if true, render cell appropriately. For example, put a
special border on the cell, if the cell can be edited, render in the color
used to indicate editing
row - the row index of the cell being drawn. When drawing the header,
the value of row is -1
column - the column index of the cell being drawn
Note that the Object being passed in is not, as you have written, the
checkbox, but the value of the cell. So you'll have to get this Object's
boolean value and then your renderer will use JCheckbox's setSelected( )
method to indicate whether it's checked or not.
Doing just this much research in the api documents and tutorial will
probably give you the rest of the information you need, or lead you to the
answers you seek, which will likely include information about cell editors.
"Ben Munday" <benny111@hotmail.com> wrote in message
news:400613be$1@duster.adelaide.on.net...
> 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);
>
Re: Help to solve flickering Checkbox in JTable
Author: perry
Date: Sat, 01 May 2004 21:43
Date: Sat, 01 May 2004 21:43
45 lines
3034 bytes
3034 bytes
what version of jdk are you using?
Ben Munday wrote:
> 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);
>
Re: Help to solve flickering Checkbox in JTable
Author: Andrew Thompson
Date: Mon, 03 May 2004 01:19
Date: Mon, 03 May 2004 01:19
22 lines
1974 bytes
1974 bytes
>> I have a problem with a Checkbox in a JTable. It's a bad idea to mix AWT and Swing. <http://www.physci.org/guifaq.jsp> Speaking of bad ideas, (you seem to be on a roll) please do not cross-post. <http://www.physci.org/codes/javafaq.jsp#xpost> (note that two of the groups to which you are posting are not valid groups) For valid groups, check here. <http://www.physci.org/codes/javafaq.jsp#groups> F'Ups set to c.l.j.help.. -- Andrew Thompson http://www.PhySci.org/ Open-source software suite http://www.PhySci.org/codes/ Web & IT Help http://www.1point1C.org/ Science & Technology
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads