• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Removing graphical trash from JLayeredPane

 
Greenhorn
Posts: 1
C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody!
Help me to remove this graphical artifact from JLayeredPane:

There is a simple app with drawing panel(Scene) inherited from JLayeredPane and graphical objects on it - inherited from JComponent with overridden paintComponent():

If zoom == 1.0 ( g.scale(1.0, 1.0) in Scene's paint() method ) it's OK - moving objects in scene dont lead to graphical artifacts:


But if I set zoom greater or lower than 1.0, I've got some bugs while moving objects by mouse:


How to remove this "trace"?

Thank you!



 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JComponent doesn't repaint its background. So I'm guessing you need to add code to do this in the paintComponent() method. Something like:

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or extend JPanel instead of JComponent; don't forget to call super.paintComponent(g) as the first statement in the overridden paintComponent method, or you'll get the same result.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic