This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Removing graphical trash from JLayeredPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Removing graphical trash from JLayeredPane" Watch "Removing graphical trash from JLayeredPane" New topic
Author

Removing graphical trash from JLayeredPane

Andrew Ryaskov
Greenhorn

Joined: Dec 15, 2011
Posts: 1

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!



Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
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:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing graphical trash from JLayeredPane
 
Similar Threads
PA #1.....picture association
Insider's Guide to Mixing Swing and JavaFX
Help with GridBagLayout resize behaviour
Gui is running fine, don't know exactly how to code
TOMCAT SSL - beginner problem