Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding a JPanel to a JFrame

 
Richard Cook
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Cook wrote: . . . Netbeans Mattise . . .
Most of us believe you learn nothing or less by using a GUI builder.
 
Mithil Wane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic