QMCS 230: Today in Class - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

QMCS 230: Today in Class

Description:

R. Smith - University of St Thomas - Minnesota. QMCS 230: Today in Class ... R. Smith - University of St Thomas - Minnesota. That's it. Questions? Creative ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 14
Provided by: ricks6
Category:
Tags: qmcs | class | st | thomas | today

less

Transcript and Presenter's Notes

Title: QMCS 230: Today in Class


1
QMCS 230 Today in Class
  • Project Proposals Due Today!
  • Identify your task and
  • (if any) your team mates
  • Layout Managers
  • Flow
  • Border
  • Grid
  • (Were skipping Section 7.3)

2
Why, why why?
  • Why do we have to put a panel inside a window
    when we create a GUI?
  • In a sensible world, why bother?
  • Both are in fact Container objects
  • Why isnt the window enough by itself?

3
Layout Managers
  • The answer to this little mystery
  • A standard window uses the Border layout by
    default.
  • A standard panel uses the Flow layout by
    default.
  • Weve been using Flow. What does it do?

4
How Flow Works
  • Each GUI component (button, label, text box,
    etc.) is added left-to-right, top-to-bottom
  • The layout adapts to the window size
  • Each component keeps its natural size
  • The only controls available alignment, gaps
  • FlowLayout.LEFT, FlowLayout.RIGHT,
    FlowLayout.CENTER
  • Horizontal and vertical minimum gaps between items

5
Controlling the Layout
  • Choosing the Layout Manager
  • JPanel panel new JPanel()
  • panel.setLayout(new BorderLayout())
  • A layout manager is an object you create the
    kind of manager (object) you want and give it to
    your container/panel/window
  • Setting parameters
  • Usually done with the object constructor

6
FlowLayout constructors
  • FlowLayout(FlowLayout.LEFT) alignment
  • Alignment affects every item in the container
  • With 3 arguments FlowLayout(A, B, C)
  • A the desired alignment
  • B the horizontal gap in pixels
  • C the vertical gap in pixels

7
BorderLayout Manager
BorderLayout manages five regions where
components can be placed.
8
BorderLayout Manager
  • New windows are BorderLayout by default
  • A component placed into a container that is
    managed by a BorderLayout must be placed into one
    of five regions
  • BorderLayout.NORTH
  • BorderLayout.SOUTH
  • BorderLayout.EAST
  • BorderLayout.WEST
  • BorderLayout.CENTER
  • By default it goes in the center region

9
How BorderLayout Works
  • Each item goes into a specific region
  • Whats the default again?
  • Each region holds ONLY ONE item at a time
  • Each item is RESIZED to fit the region
  • If too small, it expands to fill the region
  • If too large, it shows as much as it can
  • How do we get around all this?
  • Hint whats the default layout for ALL windows?

10
GridLayout Manager
GridLayout creates a grid with rows and columns,
much like a spreadsheet. A container that is
managed by a GridLayout object is divided into
equally sized cells.
columns





rows
11
Setting up a GridLayout
  • Constructor takes 2 arguments
  • Rows
  • Columns
  • One or other may be 0, but not both
  • Like BorderLayout
  • Each region contains ONLY ONE object
  • The object in a region is RESIZED to fill the
    region
  • Question how do we get around this problem?

12
GridLayout Manager
  • Components are added to a GridLayout in the
    following order (for a 55 grid)

ExampleGridWindow.java GridLayout also accepts
nested components ExampleGridPanelWindow.java
13
Thats it.
  • Questions?
  • Creative Commons License
  • This work is licensed under the Creative Commons
    Attribution-Share Alike 3.0 United States
    License. To view a copy of this license, visit
    http//creativecommons.org/licenses/by-sa/3.0/us/
    or send a letter to Creative Commons, 171 Second
    Street, Suite 300, San Francisco, California,
    94105, USA.
Write a Comment
User Comments (0)
About PowerShow.com