O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Swing Containers

In this chapter, we’ll take a look at a number of components Swing provides for grouping other components together. In AWT, such components extended java.awt.Container and included Panel, Window, Frame, and Dialog. With Swing, you get a whole new set of options, providing greater flexibility and power.

A Simple Container

Not everything in this chapter is more complex than its AWT counterpart. As proof of this claim, we’ll start the chapter with a look at the JPanel class, a very simple Swing container.

The JPanel Class

JPanel is an extension of JComponent (which, remember, extends java.awt.Container) used for grouping together other components. It gets most of its implementation from its superclasses. Typically, using JPanel amounts to instantiating it, setting a layout manager (this can be set in the constructor and defaults to a FlowLayout), and adding components to it using the add() methods inherited from Container.

Properties

JPanel does not define any new properties. Table 8.1 shows the default values that differ from those provided by JComponent.

Table 8-1. JPanel Properties

Property

Data Type

get

is

set

bound

Default Value

See also properties from the JComponent class (xref linkend="SWING-CH-3-TABLE-10"/>).       

UIClassID

String

•

   

"PanelUI"

accessibleContext*

AccessibleContext

•

   

JPanel.AccessibleJPanel()

doubleBuffered*

true

 

•

•

 

true

layout*

LayoutManager

•

 

•

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required