This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Painting on glass panel

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22573
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic