The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Background image trouble on GUI.

Hey guys, I have a little trouble concerning this GUI below. What I tried to do is to add a background to a JFrame by creating a panel whom I set as the "background" and then adding the other panels to this one. The problem is that once the program is run It does not display all the buttons until you scroll over them and it does not display the JLabels at all. Do you perhaps have a suggestion about what i could do to solve this problem?

Re: Background image trouble on GUI.

Originally Posted by Pydra

Do you perhaps have a suggestion about what i could do to solve this problem?

It's hard to know where to begin - it's a mess. You're setting the frame visible before you add any components to it, you don't call pack() on it to lay out the components, you're adding the overlay panels in the wrong order, panels are opaque by default, so you need to make the top one transparent, setting bounds or sizes on GridLayout components is pointless because it sizes them to fit the grid - you should use the hgap andvgap constructor arguments (read the API docs!), and a panel border if needed... etc. I got bored at that point.

Even if you reworked that code into something reasonable, Kevin's suggestion is just so much cleaner and simpler.