Upload
alaina-bridges
View
212
Download
0
Embed Size (px)
Citation preview
CPSC 233 TutorialXin Apr 6, 2011
Reading files An example available on my website
pages.cpsc.ucalgary.ca/~liuxin
Layout manager describe how components are arranged
Add a layout manager to Jframe eg., framWindow.setLayout(new
BorderLayout());
Designate positions in the add() method eg., add(button, BorderLayout.SOUTH);
Java build-in layout mangers BorderLayout, GridLayout, GridBagLayout, etc.
BorderLayout Place components into five regions
NORTH, SOUTH, EAST, WEST, CENTER
add(button, BorderLayout.SOUTH)
BorderLayout.NORTH
BorderLayout.WEST
BorderLayout.EAST
BorderLayout.SOUTH
FlowLayout Arranges components one after the other
from left to right in the order in which components are added
GridLayout Arrages components in a 2D grid.
(0, 0) (0, 1) (0, 2) (0, 3)
(1, 0) (1, 1) (1, 2) (1, 3)
(2, 0) (2, 1) (2, 2) (2, 3)
Grid Bag Layout A flexible and powerful layout manager.
places components in a 2D grid
Allow specified components to span multiple rows or columns
Uses components’ preferred sizes to determine how big the cells should be
A good online tutorial: http://download.oracle.com/javase/tutorial/uiswing/layout/gridbag.html
An example from Sun http://download.oracle.com/javase/tutorial/ui
swing/layout/gridbag.html
Work with GridBagLayout
Specifying constraints with GridBagConstraints
frameWindow.setLayout (new GridBagLayout());GridBagConstraints c = new GridBagConstraints();//For each component to be added to this container://...Create the component...//...Set instance variables in the GridBagConstraints instance...pane.add(theComponent, c);
GridBagConstraints Attributes to set up
gridx, gridy gridwidth, gridheight fill
NONE, HORIZONTAL, VERTICAL, or BOTH ipadx, ipady
internal padding insects
external padding anchor
CENTER, PAGE_START, PAGE_END, … weightx, weighty
determine how to distribute space among columns and rows
James’ Example For your in-class practice