aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GUI and repaint() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI and repaint()" Watch "GUI and repaint()" New topic
Author

GUI and repaint()

Joseph Cho
Ranch Hand

Joined: Feb 19, 2012
Posts: 42
I'm having an issue everytime I use mouse listener to call repaint().. It keeps printing like a snapshot of the Frame over the other one, only once.. Can someone help me figure out why? I don't understand what is happening enough to troubleshoot this issues. Thank you.

Here is my whole code if you want to copy and paste to run it. The issue lies in the TileCanvas sub class

Joseph Cho
Ranch Hand

Joined: Feb 19, 2012
Posts: 42
never mind.. I fixed it. It was the way I was calling repaint.

I used frame.repaint(); and it resolved my issue.
Joseph Cho
Ranch Hand

Joined: Feb 19, 2012
Posts: 42
I edited my code above.. using fram.repaint(); resets the page though, what I want to do, is is have it repaint the current grid which is in the TileCanvas class. but when i call just repaint().. i get a copy of the grid moved down a little painted over the original..

any ideas?
Joseph Cho
Ranch Hand

Joined: Feb 19, 2012
Posts: 42
Nevermind I fixed it.. I just used, frame.repaint().. and then just refilled the grid on any refresh..

Felt good to fix it. ;)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
I shall move this to our GUIs forum, where we usually discuss such questions.

But why are you using a MouseListener in the first place? [Edit]I can now see why you want a MouseListener[/edit]
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Jef Cho wrote:what I want to do, is is have it repaint the current grid which is in the TileCanvas class. but when i call just repaint().. i get a copy of the grid moved down a little painted over the original.

That's because you neglected to invoke the super implementation, which does the default painting of a blank background.Looks like you could benefit by going through the tutorial.


luck, db
There are no new questions, but there may be new answers.
Joseph Cho
Ranch Hand

Joined: Feb 19, 2012
Posts: 42
Ahh, gosh darn it. Yea I implemented a work around but for future projects I will be reading the tutorial shortly. The book im using is "Head First Java." So it really only scratches the surface on this topic.

Thanks again!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: GUI and repaint()
 
Similar Threads
JToggleButton Question
Image on a JButton
Opening a new window.
change font in JPanel
How do you get the JButton name