COSC4840 Software Engineering - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

COSC4840 Software Engineering

Description:

A layout manager determines positions of visual components ... A BorderLayout places components in up to five areas: top, bottom, left, right, and center. ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 14
Provided by: Nad972
Category:

less

Transcript and Presenter's Notes

Title: COSC4840 Software Engineering


1
COSC-4840 Software Engineering
  • Lab Session 5
  • Layout Managers in Java
  • Or
  • How Do I Get My GUI to Look Right?
  • Prepared by Nadya Kuzmina
  • Based on Creating a GUI with JFC/Swing Trail in
    The Java Tutorial

2
Layout Managers
  • A layout manager determines positions of visual
    components within their container.
  • It is specified on the container.

3
BorderLayout 1
  • A BorderLayout places components in up to five
    areas top, bottom, left, right, and center.
  • All extra space is placed in the center area.

4
BoxLayout 1
  • The BoxLayout class puts components in a single
    row or column.
  • It respects the components' requested maximum
    sizes and also lets you align components.

5
CardLayout 1
  • The CardLayout class lets you implement an area
    that contains different components at different
    times.
  • A CardLayout is often controlled by a combo box,
    with the state of the combo box determining which
    panel (group of components) the CardLayout
    displays.

6
FlowLayout 1
  • FlowLayout is the default layout manager for
    every JPanel.
  • It simply lays out components in a single row,
    starting a new row if its container isn't
    sufficiently wide.

7
GridBagLayout 1
  • GridBagLayout is a sophisticated, flexible layout
    manager.
  • It aligns components by placing them within a
    grid of cells, allowing some components to span
    more than one cell.
  • The rows in the grid can have different heights,
    and grid columns can have different widths.

8
GridLayout 1
  • GridLayout simply makes a bunch of components
    equal in size and displays them in the requested
    number of rows and columns.

9
FlowLayout 1
  • FlowLayout puts components in a row, sized at
    their preferred size.
  • If the horizontal space in the container is too
    small to put all the components in one row,
    FlowLayout uses multiple rows.
  • If the container is wider than necessary for a
    row of components, the row is, by default,
    centered horizontally within the container.

10
BorderLayout 1
  • A BorderLayout has five areas.
  • These areas are specified by the BorderLayout
    constants NORTH, WEST, EAST, SOUTH, and CENTER.
  • It is recommended that you specify the
    component's location (for example,
    BorderLayout.SOUTH) as one of the arguments to
    the add method. If you leave it out, the
    component will be added to the center, but your
    code will be much less clear.
  • If you find that a component is missing from a
    container controlled by a BorderLayout, make sure
    that you specified the component's location and
    that you didn't put another component in the same
    location.

11
GridBagLayout 1
  • GridBagLayout is one of the most flexible and
    complex layout managers the Java platform
    provides.
  • A GridBagLayout places components in a grid of
    rows and columns, allowing specified components
    to span multiple rows or columns.
  • Not all rows necessarily have the same height.
    Similarly, not all columns necessarily have the
    same width.
  • Essentially, GridBagLayout places components in
    rectangles (cells) in a grid, and then uses the
    components' preferred sizes to determine how big
    the cells should be.

12
GridBagLayout Constraints
  • GridBagConstraints gridBagConstraints4 new
    GridBagConstraints()
  • gridBagConstraints4.insets new Insets(20, 1,
    22, 6)
  • gridBagConstraints4.gridx 1
  • gridBagConstraints4.gridy 2
  • gridBagConstraints4.ipadx 23
  • gridBagConstraints4.ipady 6
  • gridBagConstraints4.gridwidth 2

13
References.
  • 1 The Java Tutorial
  • Creating a GUI with JFC/Swing Trail
    (http//java.sun.com/docs/books/tutorial/reallybig
    index.htmluiswing).
Write a Comment
User Comments (0)
About PowerShow.com