wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Painting on glass panel" Watch "Painting on glass panel" New topic

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

Joined: Oct 27, 2005
Posts: 19651

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

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.

subject: Painting on glass panel
Similar Threads
How to use JSlider to adjust Text in a JPanel
drawing arrows
Applets - beginner
Problems with a program...
Zooming in and out - cursor not in the right place