Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

WHAT YOU’LL LEARN IN
THIS HOUR:
.Creating a layout manager
.Assigning a layout manager
to a container
.Using panels to organize
components in an interface
.Working with unusual
layouts
.Creating a prototype for a
Java application

When you begin designing graphical user interfaces (GUI) for your Java
programs, one obstacle you face is that your components can move
around. Whenever a container changes size—such as when a user resizes a
frame—the components it holds may rearrange themselves to fit its new
dimensions.


This fluidity works in your favor because it takes into account the differ-
ences in how interface components are displayed on different operating
systems. Aclickable button might look different in Windows than it does
in Linux or Mac OS.


Components are organized in an interface by using a set of classes called
layout managers. These classes define how components are displayed within
a container. Each container in an interface can have its own layout manager.


Using Layout Managers


In Java, the placement of components within a container depends on the
size of other components and the height and width of the container. The
layout of buttons, text fields, and other components can be affected by the
following things:


. The size of the container
. The size of other components and containers
. The layout manager that is being used


There are several layout managersyou can use to affect how components
are shown. The default manager for panels is the FlowLayoutclass in the
java.awtpackage, which was used during the previous hour.


HOUR 14


Laying Out a User Interface

Free download pdf