Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2004

Tip: Looking for answers? Try searching our database.

JTable refresh problem

Thread view: 
mitch gart - 12 Oct 2004 18:34 GMT
I have a JTable where I paint some of the cell backgrounds with
a custom renderer.  getTableCellRendererComponent() paints with
drawLine() and fillRect() and that sort of thing.  It's all working
fine but when I drag another window over the JTable, or when I
scroll it, sometimes it's not getting repainted correctly.
Any ideas how to make it refresh or repaint itself at the right
times?  

I looked in the group archives and there were a lot of other messages
but they were about when a table's content changes dynamically.
I'm not changing the content, I'm just trying to get the table
to keep the correct content when scrolled and when other windows
pass over it.

Thanks in advance,

- Mitch Gart
Andrew Thompson - 12 Oct 2004 19:15 GMT
> Any ideas how to make it refresh or repaint
> itself at the right times?

I'd say the problem is in your code,
the (SHORT) code you did not post..
<http://www.physci.org/codes/sscce.jsp>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.lensescapes.com/  Images that escape the mundane

mitch gart - 13 Oct 2004 20:55 GMT
> > Any ideas how to make it refresh or repaint
> > itself at the right times?
>
> I'd say the problem is in your code,
> the (SHORT) code you did not post..
> <http://www.physci.org/codes/sscce.jsp>

I figured out the problem.  In my custom component's method

     public void paintComponent(Graphics g) {

I was painting the component into g.getClipRect().
This works if it's being called for a complete table cell.
But if the cell is being scrolled and it's called for a
partial cell, it just paints on the clip region, which
doesn't look right.  The way to do it is to paint in
the whole table cell which is gotten from:

     _table.getCellRect(_row, _column, true)

- Mitch
Christian Kaufhold - 14 Oct 2004 15:46 GMT
>> > Any ideas how to make it refresh or repaint
>> > itself at the right times?
[quoted text clipped - 6 lines]
>
>      public void paintComponent(Graphics g) {
      ^^^^^^
      protected

> I was painting the component into g.getClipRect().
> This works if it's being called for a complete table cell.
[quoted text clipped - 4 lines]
>
>      _table.getCellRect(_row, _column, true)

Incomprehensible. There is no need to paint outside the clipping region
(as nothing can be painted there anyway). Please post your code.

Christian
Signature

And in short, I was afraid.

Bryan E. Boone - 19 Oct 2004 17:05 GMT
>>>>Any ideas how to make it refresh or repaint
>>>>itself at the right times?
[quoted text clipped - 24 lines]
>
> Christian
...Also, if you're inside the custom renderer (I assume some kind of
Component implementing the renderer interface),
there's no need to call _table.getCellRect(...).
You have the rectangle as in:
Rectangle r = new Rectangle(getSize());
...That being said... Please post your code.
-Bryan


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.