wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Adding a JPanel to a JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding a JPanel to a JFrame" Watch "Adding a JPanel to a JFrame" New topic
Author

Adding a JPanel to a JFrame

Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
Hi ya,

I am trying to add a panel to a form.

essentially what I am doing is creating a panel for a toolbox window which i want to be non resizable.

So I am doing the following:


The problem is I am getting a blank Frame appear.

If anyone can help I would be much appreciated as it is getting quite frustrating.

MAny thanks in advance.


Regards


Richard
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Welcome to the Ranch.

You need to set some sort of size, or bounds for your frame before trying to make it visible.
When you see the frame, the panel will be inconspicuous, because you can't see it until you do something to it. Try setting the background of the panel to a particular colour with the java.awt.Color class.

All the methods are in the documentation for JPanel and JFrame, but you might have to hunt through the blocks of "methods inherited from . . . " to find them.
Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
Many thanks for the reply.

I am not used to using swing, I am a sever side developer.

The trouble is that I am using Netbeans Mattise to design the panel, I was hoping the frame resized to the current panel size as set by the layout manager.

I assumed this due to another form that has dynaming panels resizes the frame to the panel size (which I might add I don't want to happen on that particular frame lol)

Nightmare!

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Richard Cook wrote: . . . Netbeans Mattise . . .
A lot of books, eg Deitel and Deitel, Horstmann and Cornell, which you will find in our book review pages have good introductions to Swing in. So do the Java™ Tutorials, but I worry about their use of addXXXListener(this) passim.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Richard Cook wrote: . . . Netbeans Mattise . . .
Most of us believe you learn nothing or less by using a GUI builder.
Mithil Wane
Greenhorn

Joined: Sep 10, 2006
Posts: 5
Hi,

Making a frame with a panel inside is a very easy thing. You can easily do it by having a look at Java Tutorials.
If you are designing with Matisse please check what Layout does Netbeans use as default. Also its a good idea to use background color or Line Borders while debugging so you know your components are where you have placed them.

Regards
Mithil
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
"Mithilwane" you have been warned before about your displayed name. Please go to "my profile" and change it to match our naming policy.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Adding a JPanel to a JFrame