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:
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.