• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding a contentPane to JFrame  RSS feed

 
Tesla Doty
Greenhorn
Posts: 10
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program loads, but nothing shows. I did some research and saw that I needed to set the JFrame to visible at the bottom of the frame section. I made the change, but it still does not show anything. Do I need to add everything that I added to the content pane to the frame? From my understanding you add elements to the panel, the panel to the contentPane, then the pane to the frame...

 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You create a JFrame at line 85, but you don't add any components to it. That's why when you set it to be visible, you don't see any components.

But your UserInformation class extends JFrame -- what's the point of that if you don't ever create a UserInformation object? And you've got a createContentPane() method which does a lot of things with components, but it's never called, so that doesn't help.

Here's how you should clean it up, in my opinion. First of all, don't have your program extend JFrame. (You used to see that a lot in old tutorials but it's really unnecessary.) Instead do what you're already doing in your main method. Create a JFrame, add the components to it (that's the part you're missing), and set it visible.
 
Tesla Doty
Greenhorn
Posts: 10
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Paul. That was very helpful. I see now my errors. The book we are using for this class is old and so confusing! The assignments require things be done in very confusing and difficult ways (like repetitive if else statements instead of using loops to reduce the amount of code).

Now my problem is adding the panels to the JFrame. Should the Frame be in a different section?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!