AWT Layout Managers Chapter 10 Java Certification Study

  • Slides: 15
Download presentation
AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth

AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth

Layout Managers Grid. Layout Border. Layout Flow. Layout. Manager

Layout Managers Grid. Layout Border. Layout Flow. Layout. Manager

Layout Managers • Removes repetitious need to lay out components precisely. • Insulates developer

Layout Managers • Removes repetitious need to lay out components precisely. • Insulates developer from the fact that components have different sizes when instantiated on different platforms. • All implement java. awt. Layout. Manager interface.

Containers vs. Components • Container extends Component • Components are things like Button and

Containers vs. Components • Container extends Component • Components are things like Button and Checkbox. • Containers contain Components

Hierarchy Sample (from Roberts, Figure 10. 4) Frame Panel Label Text Field Scrollbar Button

Hierarchy Sample (from Roberts, Figure 10. 4) Frame Panel Label Text Field Scrollbar Button Panel

Defaults • Panel = Flow. Layout • Applet = Flow. Layout • Frame =

Defaults • Panel = Flow. Layout • Applet = Flow. Layout • Frame = Border. Layout

Constructing a Panel • Construct the panel (new Panel()). • Give the panel a

Constructing a Panel • Construct the panel (new Panel()). • Give the panel a layout manager (set. Layout()) • Populate the panel (add()) • Add the panel to its own container (add()).

Component Size and Position • Sizes and positions are merely suggestions, overridden by the

Component Size and Position • Sizes and positions are merely suggestions, overridden by the Layout. Manager. • Each Component has a preferred size, which is “just big enough” to display the component.

Flow. Layout Manager • Default type for Panels and Applets. • A lot like

Flow. Layout Manager • Default type for Panels and Applets. • A lot like a word processor: – Arranges components in horizontal rows. – Components “wrap” to the next line if they don’t fit across. • Honors a component’s preferred size. • Specify in constructor: – Flow. Layout. LEFT, Flow. Layout. CENTER, Flow. Layout. RIGHT

Grid. Layout Manager • Grid. Layout( rows, columns ) • Forces a size on

Grid. Layout Manager • Grid. Layout( rows, columns ) • Forces a size on a component equal to the size of the cell. • add( component ) - Adds from left to right.

Border. Layout Manager “North” “West” “Center” “South” “East”

Border. Layout Manager “North” “West” “Center” “South” “East”

Border. Layout Manager • North and South – Honors preferred height – Forces width

Border. Layout Manager • North and South – Honors preferred height – Forces width to width of container • East and West – Honors preferred width – Forces height to height of container. • Remainder of space given to center. • add( component, String )

“Find the Layout Manager” • Refer to 10. 4 and find the following Layout

“Find the Layout Manager” • Refer to 10. 4 and find the following Layout Managers: – (1) Border. Layout – (4) Grid. Layout – (1) Flow. Layout

Other Layout Managers • • Grid. Bag Layour Manager Card Layout Manager No Layout

Other Layout Managers • • Grid. Bag Layour Manager Card Layout Manager No Layout Manager Create Your Own Layout Manager

References • All Material in this Presentation is heavily based on: Roberts, Simon and

References • All Material in this Presentation is heavily based on: Roberts, Simon and Heller, Philip, Java 1. 1 Certification Study Guide, 1997: SYBEX™. ISBN: 0 -7821 -2069 -5 • Selected portions from JDK 1. 1. 6 Java. Doc HTML pages.