CISC 370 Lecture Notes for Class No. 14 March 23, 2000

Course Home Prev Lect Next Lect Example Progs Exercise Solns
CoreJava Progs
Documentation
Gen'l Docs Java 2 APIs Java Glossary Term Proj Info

Assignment

Reading:
Horstmann & Cornell, chap 9, esp the material on layout managers. This is one of the better explanations of layout managers that I have seen and you should study these pages carefully.
Exercises: See previous lecture

Today's Lecture Topics

  1. Flow layout manager

  2. Border layout manager

  3. Card layout manager

    A stack of components. We use this layout manager in an example that cycles through a series of slides for a lecture.

  4. Grid layout manager

    One problem with the color canvas example that we did last time was the size of the scroll bars. They were a bit too small as shown below.

    Larger scroll bars would provide better control, but the flow layout manager sized the bars. We can increase the size of the scroll bars by switching to the Grid Layout manager for the bottom panel. The Grid Layout maanger lays out components on an m x n (m rows and n columns) grid in which each component is the same size. So we will choose a 1 x 6 grid that will divide the bottom panel into six equal parts and each scroll bar will be one-sixth the overall width of the frame. However, in this case the labels will be too far from the scrollbars as they are, by default, left justified in their component. In this case, we can use a 2nd arg for the Label construtor that tells how to align the label, either LEFT, CENTER, or RIGHT. We can also use this device to make the distances between the labels and text fields at the top more uniform (this was a problem we discussed the previous lecture).

    These changes give us version-2 of our color canvas . It produces the following window

    A nice, different version is given in Horstmann & Cornell , chap 9, p. 399-401 (but there is no interaction between the text and the scrollbar as there is in the first two versions). It also uses a grid layout manager to layout the scroll bars, but uses a different arrangement. It produces the following window.

    Here is another grid layout example, the phone pad and the image it creates.

  5. Grid bag layout manager

Back to the CISC 370 homepage.

Corrections, suggestions and comments to Bob Caviness

Copyright 2000 B. F. Caviness