• 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

Problem with Graphics

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrrgh. Maybe its the protected keyword. Will try.
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote: . . . something gets overwritten

Careful about spellings. You mean "overridden", surely?
 
reply
    Bookmark Topic Watch Topic
  • New Topic