aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Painting on glass panel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Painting on glass panel" Watch "Painting on glass panel" New topic
Author

Painting on glass panel

Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
I have a class which extends from JComponent and it paints string (with help of Swing Timer) which is moving and changing.

Whenever my opaque glass panel gets repainted then will content panel too, how I could repaint it from particular area only (glass and content panels) like bounds of the string.

Major problem is clearly the CPU usage, because of the repainting of whole area. This ins't so important for me right now but I'm grateful for any reply. Because in future I could write some nice floating, moving and iconed menu component on glass panel.

Like JTable paints dirty regions (cells) ???

Some code (what the hell, here is the whole code):

Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
>> Maybe I will use opaque CellRendererPane for this one
forget that...

Umm, what I mean was maybe content panel could act like CellRendererPane by painting dirty regions, in area where glass panel is painting ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

java.awt.Component has two extra repaint methods. One takes 4 integers specifying the region, the other takes an additional delay in milliseconds.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
I know but, I think it's not that simple. Maybe I google how to paint dirty regions.
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
Ok, it was quite easy, well... no playing with RepaintManager...

Added atribute on constructor of JTextTraveller (JComponent parentContainer), in this case parentContainer is JRootPane and I fixed workflow of DoTextAndPaint's done() method:



Umm, CPU usage is gone, but guess is that I will have to do a little bit of optimization for this too. That it will be painted correctly in any cases.


EDIT I: little 'if else' condition

EDIT II: bunch of improved methods

Yes it's non-opaque, and here is how to try it.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Painting on glass panel