Download presentation
Presentation is loading. Please wait.
Published byAlaina Bridges Modified over 9 years ago
1
CPSC 233 Tutorial Xin Apr 6, 2011
2
Reading files An example available on my website pages.cpsc.ucalgary.ca/~liuxin
3
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.
4
BorderLayout Place components into five regions NORTH, SOUTH, EAST, WEST, CENTER add(button, BorderLayout.SOUTH) BorderLayout.NORTH BorderLayout.WE ST BorderLayout.EA ST BorderLayout.SOUTH
5
FlowLayout Arranges components one after the other from left to right in the order in which components are added
6
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)
7
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/uiswin g/layout/gridbag.html http://download.oracle.com/javase/tutorial/uiswin g/layout/gridbag.html
8
An example from Sun http://download.oracle.com/javase/tutorial/uiswin g/layout/gridbag.html http://download.oracle.com/javase/tutorial/uiswin g/layout/gridbag.html
9
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);
10
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
11
James’ Example For your in-class practice
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.