aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes TableCellRenderer based on JComponent executing but nothing shows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "TableCellRenderer based on JComponent executing but nothing shows" Watch "TableCellRenderer based on JComponent executing but nothing shows" New topic
Author

TableCellRenderer based on JComponent executing but nothing shows

Malcolm Storey
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
I found a simple pie-chart class on the web. It works fine in normal use. I added implements TableCellRenderer and used it as a CellRenderer but the pie charts don't show in the cells. (For simplicity, the chart isn't yet connected to any data.)

It tried changing paint to paintComponent but it made no difference.

I've followed it through with the debugger: getTableCellRendererComponent is being executed for the right column in the JTable and paint is being called for each cell.



Malcolm

I wouldn't join any Collection with an add() method that would accept me as a parameter
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

You probably just need to override getPreferredSize() to return an appropriate Dimension.


luck, db
There are no new questions, but there may be new answers.
Malcolm Storey
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
override getPreferredSize()


Thanks for the suggestion, but it didn't fix it.
Malcolm Storey
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
I've overridden all three



The debugger shows that none of them are called.

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

Is getTableCellRendererComponent(...) called?
Malcolm Storey
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
Is getTableCellRendererComponent(...) called?


Yes. Once, for that column, in each row (as expected)
Malcolm Storey
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
Progress at last!

If I change

to

it works.

getBounds returned x=196, y=0, w=26, h=15

g.getClipBounds returns 0,0,26,15

This was more by trying things than understanding what was happening. Presumably different coord systems?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

Good for you that you fixed it, but you don't need either of getBounds() or g.getClipBounds(). Just use getWidth() and getHeight().

The Rectangle returned from getBounds() is always in the coordinate system of the parent Container.

Your custom drawing always needs a top left of [0, 0] in the coordinate system of the Component being painted. Which is always [0, 0] in the coordinate system of the passed in Graphics parameter.
Malcolm Storey
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
Thanks Darryl.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TableCellRenderer based on JComponent executing but nothing shows