1 / 15

AWT Layout Managers (Chapter 10)

AWT Layout Managers (Chapter 10). Java Certification Study Group January 21, 1999 Mark Roth. GridLayout. BorderLayout. LayoutManager. FlowLayout. Layout Managers. Layout Managers. Removes repetitious need to lay out components precisely.

arleen
Download Presentation

AWT Layout Managers (Chapter 10)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. GridLayout BorderLayout LayoutManager FlowLayout Layout Managers

  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 Panel Panel Panel Label Label Label Text Field Text Field Text Field Scrollbar Scrollbar Scrollbar Panel Button Button 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” “West” “East” “South”

  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.

More Related