SE1020 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

SE1020

Description:

In using this layout, GUI components are placed in left-to-right order. ... Components are placed in top-to-bottom, left-to-right order. ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 16
Provided by: drmarkh
Category:

less

Transcript and Presenter's Notes

Title: SE1020


1
Creating Graphical User Interfaces
2
Placing GUI components on a JFrame
  • There are two ways to put GUI components on the
    content pane of a JFrame
  • Absolute positioning
  • You explicitly specify the position and size of
    GUI objects within the content pane
  • btnQuit.setBounds( 10, 125, 80, 30 )
  • Use a Layout Manager
  • A class that controls automatic placement of
    components

3
Layout Managers automatically determine how the
GUI components appear within the container
  • Many different layout managers exist some are
  • FlowLayout
  • BorderLayout
  • GridLayout
  • To use, set the layout manager of a JFrames
    Container to the type of layout manager you want
    to use
  • FlowLayout fl new FlowLayout(FlowLayout.CENTER)
    contentPane.setLayout(fl)

4
Using FlowLayout
  • In using this layout, GUI components are placed
    in left-to-right order.
  • When the component does not fit on the same line,
    left-to-right placement continues on the next
    line.
  • As a default, components on each line are
    centered.

5
FlowLayout behavior when the frame containing the
components is resized
6
BorderLayout
  • This layout manager divides the container into
    five regions center, north, south, east, and
    west.
  • Not all regions have to be occupied.

7
BorderLayout resizing
  • The north and south regions expand or shrink in
    width only
  • The east and west regions expand or shrink in
    height only
  • The center region expands or shrinks on both
    height and width.

8
GridLayout
  • Places GUI components on equal-size N by M grids.
  • Components are placed in top-to-bottom,
    left-to-right order.
  • Number of rows and columns remains the same after
    the frame is resized, but the width and height of
    each region will change.

9
GridLayout resizing
10
Complex layouts
  • For sophisticated GUIs, it can be difficult to
    use a single layout manager to get the look you
    are after.
  • Another approach is to use panels
  • Multiple panels can be placed in a content pane
  • The class that implements a panel is JPanel

Panel 1
Panel 3
Panel 3
11
Using Panels
  • Panels can be placed on a JFrame
  • using absolute positioning
  • using a layout manager
  • Each panel can employ its own layout manager
  • or not
  • UI components are added to the panels, rather
    than the JFrame
  • But you can still add components to the JFrame as
    well

BorderLayoutpanel
Absolutepositioningpanel
Flow Layout panel
12
Nested Layouts
  • A panel can be placed inside another panel
  • This is called nesting panels
  • Nesting can be done to any level

Here, the East region of the outer panel contains
a border layout
13
Another nested panel example
Here, the Center region of the outer panel
contains a border layout
14
North
Center
South
15
North
Center
South
Write a Comment
User Comments (0)
About PowerShow.com