I am trying to get a lot of JButtons to display on top of a background image of the world in a JFrame.
So far, I've tried a lot of things. I tried overwriting the paint function of the JFrame to drawImage the image of the world. But whenever I repainted, the buttons got painted very quickly and then covered by the background image.
I then tried to create a JLayeredPane. Here is an excerpt of the code:
Dimension layeredPaneSize = new Dimension(1025, 740);
JLayeredPane layeredPane = new JLayeredPane();
And the only thing that happens is that the checkbox displays. Does anybody have any idea how I should proceed/what I'm doing wrong? Please let me know. Thanks
07-13-2005, 10:12 AM
The only way to do this (using std. components and overwriting the
paint/update) that I know of is to set the layout for the container (frame) to null,
use the setBounds(x,y,w,h) for each component (button) that is added to the
container, and to overwrite the update method where only the background image is
In general, mixing the default container layout/paint job with ones own
paint/update implementations seems to be a bad idea. Its a very frequent
issue in this forum.
I beleive that the best to do in such cases is to implement ones own buttons,
i.e. coding graphical objects with the desired responsiveness and layout.
Once done, these can be reused.