JTable refresh problem  
Author Message
mgart





PostPosted: 2004-10-13 1:35:00 Top

java-programmer, JTable refresh problem 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





PostPosted: 2004-10-13 2:15:00 Top

java-programmer >> JTable refresh problem On 12 Oct 2004 10:34:34 -0700, mitch gart wrote:

> 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>

--
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
 
mgart





PostPosted: 2004-10-14 3:56:00 Top

java-programmer >> JTable refresh problem Andrew Thompson <email***@***.com> wrote in message news:<email***@***.com>...
> On 12 Oct 2004 10:34:34 -0700, mitch gart wrote:
>
> > 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
 
 
usenet





PostPosted: 2004-10-14 22:46:00 Top

java-programmer >> JTable refresh problem mitch gart <email***@***.com> wrote:

> Andrew Thompson <email***@***.com> wrote in message news:<email***@***.com>...
>> On 12 Oct 2004 10:34:34 -0700, mitch gart wrote:
>>
>> > 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) {
^^^^^^
protected

> 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)

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



Christian
--
And in short, I was afraid.
 
 
Bryan E. Boone





PostPosted: 2004-10-20 0:05:00 Top

java-programmer >> JTable refresh problem Christian Kaufhold wrote:
> mitch gart <email***@***.com> wrote:
>
>
>>Andrew Thompson <email***@***.com> wrote in message news:<email***@***.com>...
>>
>>>On 12 Oct 2004 10:34:34 -0700, mitch gart wrote:
>>>
>>>
>>>>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) {
>
> ^^^^^^
> protected
>
>
>>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)
>
>
> Incomprehensible. There is no need to paint outside the clipping region
> (as nothing can be painted there anyway). Please post your code.
>
>
>
> 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