aspose file tools*
The moose likes Beginning Java and the fly likes Problem with Graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with Graphics" Watch "Problem with Graphics" New topic
Author

Problem with Graphics

Michael Boehm
Ranch Hand

Joined: Jun 02, 2010
Posts: 51
I am following the Java tutorial on 2D graphics and am playing with a class that creates a JFrame. Just for fun I want to print a message on a panel in the frame with the size of the frame after a user resizes the frame. As I have understood the tutorial, the method paintComponent is called eg. when the frame has been resized by a user.
However, in my code below, paintComponent seems to never be called after I resize the GUI. What am I missing ?

Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Hi Michael,
paintComponent is called when you resize the frame. The String you draw always changes when you resize the window.
Or are you expecting something else to happen?


Bye,
Nicola
Michael Boehm
Ranch Hand

Joined: Jun 02, 2010
Posts: 51
Arrrgh. Maybe its the protected keyword. Will try.
Michael Boehm
Ranch Hand

Joined: Jun 02, 2010
Posts: 51
Nicola Garofalo wrote:Hi Michael,
paintComponent is called when you resize the frame. The String you draw always changes when you resize the window.
Or are you expecting something else to happen?


Nothing is written on the frame when I resize
Michael Boehm
Ranch Hand

Joined: Jun 02, 2010
Posts: 51
Solved. Sorry about the herring. Apparently I didnt run the class-file I thought I did. Had compiled from two different folders so was running the old classfile from before I added painting. Sorry.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
There's a bug in the code that causes the window to be sized incorrectly. You'll find it by using @Override annotations wherever applicable :-) (you should get in the habit of using that everywhere, both to prevent bugs like this one from happening, and as a reminder to whoever reads the code in future to know that something gets overwritten).


Ping & DNS - updated with new look and Ping home screen widget
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36592
    
  16
Ulf Dittmer wrote: . . . something gets overwritten
Careful about spellings. You mean "overridden", surely?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Graphics
 
Similar Threads
Help with Scrollable Image please...
Canvas HELP!!!
Problem with custom painting and multiple JPanel
board not Drawing...
scrolls and pics and drawing