Hello, I'm trying out my first project with swing in Java and I'm missing something. The code is below. Everything works except when the window is generated it's empty, the labels are being generated (checked with system out messages) but they aren't showing up in the window. I'm not sure if the problem is bewteen the labels in the panel or the panel in the frame but something done broke :)

In your RandomPanel constructor, you created a new Panel and dressed that with your buttons but you never used that panel anywhere. Don't create a new Panel in that constructor, just set all those things on the RandomPanel with

Code:

setLayout(new GridLayout(1,3));

04-05-2011, 05:24 AM

011121

Alright I'm very very confused now. I had it the way you say originally and it was doing the same thing, then I added in the panel and it was doing the same thing, but I just took it back out and now it works.

I have no idea why. But that's not your problem. Thank you for the help!

04-05-2011, 07:21 AM

DarrylBurke

Extending JPanel and JFrame, as in your example code, is a gross misuse of inheritance. Also, as already said, constructing a JPanel within a class that extends JPanel, and ignoring the JPanel that the class represents, is meaningless.