aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Help with adding a frame to netbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help with adding a frame to netbeans" Watch "Help with adding a frame to netbeans" New topic
Author

Help with adding a frame to netbeans

Chris Swanson
Greenhorn

Joined: Nov 30, 2009
Posts: 15
I am trying to get some OOP in my netbeans project, but I am having trouble adding a simple JPanel. I used to simply add JPanels to the JFrame in the design window, but this eventually becomes rather clunky when you have several panels. Instead, I have the JPanel as a separate class. Normally, this would be a simple deal in Swing, but Netbeans is having problems. My main class is very simple.


This is in my main JFrame object. But for some reason the user login panel is not appearing. Any help on why this is happening?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Moving to our GUIs forum, where we usually discuss this sort of thing.

The first thing they will tell you there is to stop using NetBeans until you are used to GUIs. Quite correct: NetBeans produces incomprehensible GUI code.
They will also send you to the Java™ Tutorials which have loads of useful information in.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Chris Swanson wrote:I am trying to get some OOP in my netbeans project, but I am having trouble adding a simple JPanel. I used to simply add JPanels to the JFrame in the design window, but this eventually becomes rather clunky when you have several panels. Instead, I have the JPanel as a separate class. Normally, this would be a simple deal in Swing, but Netbeans is having problems. My main class is very simple.


This is in my main JFrame object. But for some reason the user login panel is not appearing. Any help on why this is happening?


You don't call setVisible on the JPanel, rather it needs to be called on the JFrame. Your program has a NetBeans created initComponents method, and I'm afeared that it is changing the layout of your JFrame's contentPane from the default BorderLayout to GroupLayout or somesuch.

I second the previous recommendation: don't use NetBeans code-generation for anything but prototyping. Instead learn Swing from the inside out using the tutorials linked to above. You may wish to start with the layout managers section.
Chris Swanson
Greenhorn

Joined: Nov 30, 2009
Posts: 15
This is in my main JFrame object. But for some reason the user login panel is not appearing. Any help on why this is happening?


You don't call setVisible on the JPanel, rather it needs to be called on the JFrame. Your program has a NetBeans created initComponents method, and I'm afeared that it is changing the layout of your JFrame's contentPane from the default BorderLayout to GroupLayout or somesuch.

I second the previous recommendation: don't use NetBeans code-generation for anything but prototyping. Instead learn Swing from the inside out using the tutorials linked to above. You may wish to start with the layout managers section.


The truth is I've worked with Swing for about 2 months, and feel I have a pretty good handle on the most important aspects. However, I am new to IDEs, and I find this problem so be very puzzling. I actually am calling the setVisible method for the JPanel within the JFrame constructor. What else could Netbeans be doing to cause something so simple not to work?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Chris Swanson wrote:
The truth is I've worked with Swing for about 2 months, and feel I have a pretty good handle on the most important aspects. However, I am new to IDEs, and I find this problem so be very puzzling. I actually am calling the setVisible method for the JPanel within the JFrame constructor. What else could Netbeans be doing to cause something so simple not to work?


Again, the key I believe is the layout. Get control of the layout, and avoid using GroupLayout which many find hard to modify by hand. The Sun layout tutorials can guide you to the one true path.
Chris Swanson
Greenhorn

Joined: Nov 30, 2009
Posts: 15
Ok, thanks. I ended up coding in a border layout and adding the object the normal way, instead of using the IDE. Worked great, thanks for the help.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
when you create a JFrame or JDialog within NetBeans, the generated code already includes displaying them when you compile and run them. you probably accidentally deleted the line of code that should have made the JFrame appear?


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
 
 
subject: Help with adding a frame to netbeans