Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Swing Components
-
We've already covered a few, but let's review them, starting with JPanels
and JFrames.
-
These two Swing components are very similar. Both are containers
of other components.
-
A JFrame is basically a window. It has a title bar, maximize, restore,
and minimize options. You can disable these if you want.
-
A JPanel is simply a container. It is more of a virtual container
than a JFrame. You can nest panels (add panels to panel) within each other,
and assign unique layouts to each panel.
-
Both JPanels and JFrames have layout managers. JFrames default to
BorderLayout, and JPanels default to FlowLayout. But of course, you
can change these.
-
Though they are invisible to the end user, JPanels have many uses.
-
Perhaps their biggest use is in nesting layout managers.
-
Also, consider layout managers like BorderLayout and GridLayout where you
can only put one component in a region or cell. What if you want
to put three JButtons or three RadioButtons in a single cell? You
first put a JPanel in the region or cell. This counts as your one
component. Then, you can set that JPanel to a FlowLayout, which can
take mutiple components, and add your buttons to that panel.
-
You can use the setLayout(LayoutManager m) method of most containers to
set the layout that you wish to use. Or, even better, just do it
graphically in Forte'.
Text Input
![](commons.jpg)
![](top01.gif)
![](top02.gif)
Created by: Brandan
Jones January 4, 2002