aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Weird displaying issues between computers? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Weird displaying issues between computers?" Watch "Weird displaying issues between computers?" New topic
Author

Weird displaying issues between computers?

Ben Jass
Ranch Hand

Joined: Sep 25, 2010
Posts: 76
Hey guys, I'm having trouble with this program I'm making. When I run it at school, everything works fine. However, when I run it at home, the program glitches up kinda like when your computer freezes up and you start seeing double windows when you try to move it? It's really hard to explain, so I took pictures to try my best to explain what is going on.

When I first start up the program it looks like this:



Now, when I click somewhere to draw a shape (part of what the program is supposed to do), it glitches up like this:



This isn't even a part of the program, I can paint over this:



Also, when I try to move the window itself, for example, let's say I move below the desktop so I can only see half of it, it will erase some of it:



Like I said, this is a really hard problem to explain, and considering that it works at school, I don't think it has to deal anything with the code itself. Both Java versions on computers are updated.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Did you overridde paintComponent and forget to call super.paintComponent as the first line?
Ben Jass
Ranch Hand

Joined: Sep 25, 2010
Posts: 76
Thanks man, that helped. One thing though, now that I call super.paintComponent(g), I can only draw one thing at a time? Is there any simple fixes too this?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Keep a List of things that need to be painted, then paint everything in that List.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Ben Jass
Ranch Hand

Joined: Sep 25, 2010
Posts: 76
Thanks, I was thinking that, I was just curious if there was any more efficient ways of doing so.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

You can create a new BufferedImage, use getGraphics to get its Graphics object, and do all your drawing to that.

Then use g.drawImage(img, 0, 0, this) in the paintComponent method to copy the contents to the panel's Graphics object. Be careful to check in the paintComponent method that the two images are still the same size, i.e. deal with the case where the window has been resized.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Here's an example of double-buffering that I copied from a website that might help:

(when I tried a similar example I had problems getting createImage() to work - it won't work if your panel isn't visible, so instead I just used something along the lines of Image bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB) instead.)

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 1791
    
    2
I was just curious if there was any more efficient ways of doing so.


It depends on your exact requirement.

Custom Painting Approaches gives working examples of both approaches suggested here as well as some pros/cons of each approach.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Weird displaying issues between computers?
 
Similar Threads
Eclipse debugging issue.
Slight problem with deleting items from a scroller.
JButton Quick Help
PA #1.....picture association
How to center a JLabel?