Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error returning the size of a JPanel?  RSS feed

 
John Meehan
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Randall Twede
Ranch Hand
Posts: 4690
8
Java Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't be embarrassed, be proud you figured it out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!