Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Painting on glass panel

 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> 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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.awt.Component has two extra repaint methods. One takes 4 integers specifying the region, the other takes an additional delay in milliseconds.
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know but, I think it's not that simple. Maybe I google how to paint dirty regions.
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic