Custom CellRenderer and paint problem.

F

farseer

first, forgive me, as i also posted this under GUI (where it is
probably more on topic), but also wanted to post it here as i find this
particular forum has been most helpful to me in the past...hope no one
mind.

I have a table which uses a custom TableCellRender.

In the code below, TColumn stores some configuration information about
a given column. if it's renderComponentType member is not equal to
"LABEL", it will return a custom component i created.
That component is called "IconLabel" and it is simply a panel with two
labels, one for an IconImage and the other for displaying the text. In
this case, my table consists of only one column out of 7 that uses
IconLabel.

Further, when ever a cell is clicked, i disabled SelectionAllowed on
the table and instead, i "outline" the ENTIRE row with a white border
to show that that row has been selected. this is accomplished by
overriding JTable's prepareRenderer method.

MY PROBLEM IS, whenever i click on a cell of the table, the entire row
is highlisted with the white outline border as it should, HOWEVER, then
i now click on a next row, the Column based on my IconLabel does NOT
reset. what i mean by that is that the border of the row i had clicked
before is still highlighted with a white border. why is this?

thanks much for any help:

here's a snippet of the code:
this determines what component to use in the renderer:
if ( tc.renderComponentType != TColumn.LABEL)
c = getComponentByTColType( stbl, tc, value.toString() );
else
c = ( JComponent ) super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, col );

this initializes IconLabel only the first time so it can be
reused(_iconLabel is a private member of the CellRenderer):
if ( tc.renderComponentType == TColumn.ICONLABEL )
{
if ( _iconLabel == null )
{
_iconLabel = new IconLabel( value.toLowerCase(),
tc.alignment);
_iconLabel.setFont( table.getFont() );
}
return _iconLabel;
}


and this is the code in my "Table" that overrides prepareRendere, below
getRowSelectionBorder simply creates a compound border to create an
outline around a row.:
public Component prepareRenderer( TableCellRenderer renderer,
int row, int column )
{
JComponent c = (JComponent) super.prepareRenderer(
renderer, row, column );


if ( !getRowSelectionAllowed( ) )
return c;

if ( isRowSelected( row ) )
c.setBorder( getRowSelectionBorder( c, column) );

return c;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top