• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Adding a contentPane to JFrame

 
Greenhorn
Posts: 10
MySQL Database Java
  • 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...

 
Marshal
Posts: 24594
55
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
MySQL Database Java
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!