my dog learned polymorphism
The moose likes Beginning Java and the fly likes Swing Stuff Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Swing Stuff" Watch "Swing Stuff" New topic

Swing Stuff

Bill Norton

Joined: Mar 29, 2001
Posts: 27
Ok, I have worked with Swing and been able to make basic GUI's, ActionListener's etc..
But I don't have a firm grasp on all the different objects.
What is the relationship between JFrame and JPanel. If I have one do I have to have the other. Do frame go into panel or vice versa? What about container's and windows?
I think some of the problem in that Swing is built on AWT which adds to the confusion.
Can anyone explain in simpler terms an overview of these classes?
I have read manuals of web pages but they all seem to say different things.
Any help would be welcome.

Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Both Frame and Panel are containers.
A Frame has a Border and Titlebar, a Panel does not.
A Frame is a sub-class of window which means that a Frame is an outermost container. Therefore you can not put a Frame in a Panel. You CAN put a Panel in any of the areas of Frame.
An Applet is a sub-class of Panel.
Frame has BorderLayout as its default LayoutManager.
Panel has FlowLayout as its default LayoutManager.
You can use Panels to stack inside each other to create your desired Look. For instance you can give a Panel a GridLayout that is 2X3 and then in each of the grid cells you can put different Panels, each doing something different, etc.
You should have a good grasp of the AWT before expanding into Swing.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: Swing Stuff
It's not a secret anymore!