Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Painting on glass panel

 
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 ?
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.

 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic