Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth."— Presentation transcript:

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

2 Layout Managers GridLayout BorderLayout FlowLayout LayoutManager

3 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.LayoutManager interface.

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

5 Hierarchy Sample (from Roberts, Figure 10.4) Frame Panel Label Text Field Scrollbar Label Text Field Scrollbar Label Text Field Scrollbar Button

6 Defaults Panel = FlowLayout Applet = FlowLayout Frame = BorderLayout

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

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

9 FlowLayout 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: –FlowLayout.LEFT, FlowLayout.CENTER, FlowLayout.RIGHT

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

11 BorderLayout Manager “Center” “North” “South” “West”“East”

12 BorderLayout 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 )

13 “Find the Layout Manager” Refer to 10.4 and find the following Layout Managers: –(1) BorderLayout –(4) GridLayout –(1) FlowLayout

14 Other Layout Managers GridBag Layour Manager Card Layout Manager No Layout Manager Create Your Own Layout Manager

15 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 JavaDoc HTML pages.


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

Similar presentations


Ads by Google