• 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

placing image on jpanel and then add other components

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have an image in a JPanel where I call the paint methode to draw the image.I want to add some buttons on top or under the image(-panel). But all I tried looks terible:
1.Add a button to the same panel: nothing happens (because i overwrite "paint")
2.I add the imagePanel and a buttonPanel to a third panel, but the size of the imagePanel is wrong. It is to small, I dont see the whole picture.
Please help, its urgent...
Thanks a lot!
Here my imagePanel:
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kay,
First, since you are using Swing you should not be overriding paint instead you should be overriding paintComponent. See the quote from Sun below.


Note: Don't override or invoke the method that calls the paintXxx methods: the paint method. Although overriding paint was legitimate in pre-Swing components, it's generally not a good thing to do in components that descend from JComponent. Unless you're careful, overriding paint would likely confuse the painting system, which relies on the JComponent implementation of the paint method for correct painting, performance enhancements, and features such as double buffering.


Second, you will need to call super.paintComponent in order for things to be drawn correctly (i.e., other components appearing above your picture).
Regards,
Manfred.
 
reply
    Bookmark Topic Watch Topic
  • New Topic