• 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

drawing a simple rectangle in a panel

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I've got a class that extends JFrame with 2 panels inside it. I'd like to draw rectangles of varying heights in the right panel, however, everything that I have tried so far has failed. The rectangle is declared globally, and its properties are defined in a method as such:

paintComponet looks like this:

At present, nothing shows up on screen. What I'd like to do is specify the rectangle to paint inside the right panel.
Any pointers would be appreciated.
Thank you all.
[ November 23, 2003: Message edited by: Malcolm White ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each component is responsible for painting its own self (by default, anyway.) If you were to move the paintComponent() method into the right JPanel (i.e., subclass JPanel and add your method) you'd find that it would work. As it is, when that JPanel is painted, it erases its region of the screen, obliterating your efforts. Alternatively, you could get this to work by again subclassing JPanel so that its paint() method did absolutely nothing -- but it would be fiddly. Easier to do it the right way.
 
Malcolm White
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Ernest for the amzingly quick response and for steering me in the direction. The program now works perfectly as expected.
Take care.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic