• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding a JPanel to a JFrame

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Cook wrote: . . . Netbeans Mattise . . .

Most of us believe you learn nothing or less by using a GUI builder.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic