• 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

Error returning the size of a JPanel?

 
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I'm trying to make a mini-Paint style program, and one of the components is creating a grid across the JPanel that lies on top of all the actual drawings, which is turned on and off by a JCheckBoxMenuItem. So I'm trying to use this code:



PowerPaintPanel is the name of the panel, and GRID_SPACING is the space between each line in the grid.

When I try to use this code, the PowerPaintPanel.getWidth() and PowerPaintPanel.getHeight() calls give me an error "Cannot make a static reference to the non-static method getHeight() from the type JComponent" (and one for getWidth()). When I substitute the hard-coded default height and width for the frame, it works beautifully, except it doesn't expand if I resize the JPanel (which is what I need it to do).

I'm at a loss of how to fix this problem. Anyone have any ideas?

This is the entire code for the Panel thus far:

 
John Meehan
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, nevermind. I figured it out. I guess I'll leave this here with the answer in case someone happens along.

I had to change PowerPaintPanel.getHeight() to this.getHeight().

I feel silly now.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
don't be embarrassed, be proud you figured it out.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic