1 / 11

CPSC 233 Tutorial

CPSC 233 Tutorial. Xin 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 ());

katen
Download Presentation

CPSC 233 Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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(newBorderLayout()); • 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)

  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.

  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/uiswing/layout/gridbag.html

  8. An example from Sun • http://download.oracle.com/javase/tutorial/uiswing/layout/gridbag.html

  9. Work with GridBagLayout • Specifying constraints with GridBagConstraints frameWindow.setLayout (new GridBagLayout()); GridBagConstraintsc = 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

More Related