Laying Out Components. What is Widget Layout?

Similar documents
What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

Layout. Dynamic layout, Swing and general layout strategies

Containers and Components

Dr. Hikmat A. M. AbdelJaber

Output in Window Systems and Toolkits

CS 251 Intermediate Programming GUIs: Components and Layout

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

Layout. Dynamic layout Layout design pattern Layout strategies

Layout. Dynamic layout Layout design pattern Layout strategies. 2.6 Layout 2

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

No SVN checkout today. Object-Oriented Design

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Introduction to the JAVA UI classes Advanced HCI IAT351

Object Oriented Design & Patterns. Part 1

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

BASICS OF GRAPHICAL APPS

Starting Out with Java: From Control Structures Through Objects Sixth Edition

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Today. cisc3120-fall2012-parsons-lectiii.3 2

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

YouTube Break.

Graphical User Interface (GUI)

Basicsof. JavaGUI and SWING

Sri Vidya College of Engineering & Technology

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

GUI in Java TalentHome Solutions

Top-Level Containers

CSC 161 SPRING 17 LAB 2-1 BORDERLAYOUT, GRIDLAYOUT, AND EVENT HANDLING

Graphical User Interfaces. Comp 152

Chapter 2 First Java Programs

Unit 6: Graphical User Interface

CSC207H: Software Design Lecture 11

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

More Swing. Chapter 14. Chapter 14 1

Lesson 2: First Java Programs

Part I: Learn Common Graphics Components

China Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert

- learnability. - efficiency. - graphic design

Java Programming Lecture 6

CS 2113 Software Engineering

2IS45 Programming

Window Interfaces Using Swing Objects

Java. GUI building with the AWT

CS11 Java. Fall Lecture 4

Graphical User Interface (GUI)

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

Lecture 5: Java Graphics

Building Graphical User Interfaces. GUI Principles

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Graphical User Interfaces (GUIs)

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

CS11 Java. Fall Lecture 3

Part 3: Graphical User Interface (GUI) & Java Applets

CSCI 201L Midterm Written SOLUTION Fall % of course grade

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

The Java Programming Language Basics. Identifiers, Keywords, and Types. Expressions and Flow Control. Object-Oriented Programming. Objects and Classes

Window Interfaces Using Swing. Chapter 12

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

Window Interfaces Using Swing Objects

Chapter 14. More Swing

Human-Computer Interaction IS4300

The MVC Design Pattern

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

Lecture 18 Java Graphics and GUIs

Dell Canvas Layout. Version 1.0 User s Guide

Building Graphical User Interfaces. Overview

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

1. Swing Note: Most of the stuff stolen from or from the jdk documentation. Most programs are modified or written by me. This section explains the

Example: Building a Java GUI

Graphical User Interfaces in Java

PIC 20A GUI with swing

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

The AWT Package, An Overview

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

CSE 331 Software Design & Implementation

Java: Graphical User Interfaces (GUI)

Chapter 6: Graphical User Interfaces

Graphic User Interfaces. - GUI concepts - Swing - AWT

More UI Output Tasks: Damage Management & Layout

JFrame In Swing, a JFrame is similar to a window in your operating system

Transcription:

Laying Out Components Interior Design for GUIs What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position Main problem: what if a window changes size? Example 1

Resizing a Window Menu wraps Buttons lost Scrollbar added In-class demo 2

Hierarchical Widget Layout Hierarchical Layout (2) 3

Size Properties When a component is instantiated, it takes on size properties Preferred size Minimum size Maximum size These properties are used to determine component size during (a) initial layout and (b) resize operations Size also affected by layout manager policies (more on this later) Example Programs DemoSizeProperties.java DemoSize.java DemoPosition.java 4

Progamming Challenge Create a new version of DemoSizeProperties that presents the component name, class, and size properties in a JTable Name the new program PC_SizeProperties.java Solution PC_SizeProperties.java 5

Widget Layout Models Absolute (aka fixed) Control for component size and position Struts and springs Control for component position Variable intrinsic size Control for component size Absolute Positioning Component position and size explicitly specified X and Y screen coordinates Width and height of component Units: pixels (typically) 6

Absolute Positioning (2) Advantages Simple to implement Widgets retain their position and size when window is resized (sometimes this is desirable) Simple to build a resource editor (drag and drop widgets onto a screen; e.g., Visual Basic) Disadvantages Difficult to change layout (too many magic numbers or defined constants) Poor response to resizing the window because Enlarging: too much empty space (ugly!) Shrinking: components lost instead of wrapping Example Program DemoAbsolute.java 7

Struts and Springs Goals Easy to use Handles window resizing appropriately Idea Add constraints to define geometric relationships between widgets Struts and Springs (2) Place struts and springs into layout Struts ( ) - fixed regions (they don t change) Springs ( ) - can be compressed or stretched Advantage When the window is resized, widget position is determined automatically by constraint equations 8

Variable Intrinsic Size Each component has intrinsic size properties (i.e., preferred size, minimum size, maximum size) During layout, components report their size properties to the layout manager (recursively, if necessary) Designers have limited control over this Some layout managers respect size properties, while others do not! Widget Communication Scenario #1: A scrollbar moves the enclosed text also moves Scenario #2: A window is resized components change in position and size How does this happen? Pseudo-events are used for widget to widget communication Pseudo because they are a responses to an implicit event (the reaction of one widget to another) Accomplished by subclassing and parent notification 9

Subclassing Most widgets are subclasses of other widgets Methods in superclass are overridden to handle updating the widget as well as notifying other widgets Parent Notification Widgets notify their parent (enclosing widget) of any changes that have occurred Parent does the right thing (e.g., ask a scrollbar for its position and move the text window) 10

Java s Layout Managers BorderLayout FlowLayout GridLayout BoxLayout GridBagLayout CardLayout OverlayLayout etc. BorderLayout Places components in one of five regions North, South, East, West, Center Support for struts and springs Struts ( ) Can specify hgap, vgap Springs ( ) Inter-component space is fixed Support for variable intrinsic size ( ) Components expand to fill space in region 11

Border Layout (2) Components expand (or stretch ) to fill space as follows Example Program DemoBorderLayout.java usage: java DemoBorderLayout where 'arg1' = strut size in pixels arg1 Example (next 2 slides) 12

Example Program No struts Invocation: java DemoBorderLayout 0 Launch Resize Variable intrinsic size Example Program With struts : hgap = vgap = 10 pixels Invocation: java DemoBorderLayout 10 Launch Resize Struts 13

FlowLayout Arranges components in a group, left-to-right (default) Group alignment: left, center, right Wraps components to new line if necessary Support for struts and springs Struts ( ) Can specify hgap, vgap Springs ( ) Inter-component space is fixed Support for variable intrinsic size ( ) Component size is fixed Space is added before/after/below the entire group of components to fill available space Example Program DemoFlowLayout.java usage: java DemoFlowLayout arg1 arg2 where 'arg1' = strut size in pixels and 'arg2' is one of c = center alignment l = left alignment r = right alignment Example (next 2 slides) 14

Example Program (2) Example Program (2) Default for FlowLayout struts : hgap = vgap = 5, alignment = center Invocation: java DemoFlowLayout 5 c Launch Resize Fill available space before/after/below group of components Example Program (3) With struts : hgap = vgap = 10, alignment = right Invocation: java DemoFlowLayout 10 r Launch Resize 15

GridLayout Arranges components in a rectangular grid The grid contains equal-size rectangles Support for struts and springs Struts ( ) Can specify hgap, vgap Springs ( ) Inter-component space is fixed Support for variable intrinsic size ( ) Components expand to fill rectangle Example Program DemoGridLayout.java usage: java DemoGridLayout arg1 where 'arg1' = strut size in pixels Example (next 2 slides) 16

Example Program (2) No struts Invocation: java DemoGridLayout 0 Launch Resize Equal-size rectangles Example Program (3) With struts : hgap = vgap = 10 Invocation: java DemoGridLayout 10 Launch Resize 17

BoxLayout Arranges components vertically or horizontally Components do not wrap Support for struts and springs Struts ( ) Can specify rigid areas Springs ( ) Can specify horizontal glue or vertical glue Support for variable intrinsic size ( ) Components expand if maximum size property is set Example Program DemoBoxLayout.java usage: java DemoBoxLayout arg1 arg2 where 'arg1' is one of c = centre alignment l = left alignment r = right alignment and 'arg2' is one of e = enable struts and springs demo d = disable struts and springs demo Example (next 2 slides) 18

Example Program (2) Invocation: java DemoBoxLayout r d Invocation: java DemoBoxLayout l d Invocation: java DemoBoxLayout c d Default is left align Example Program (3) Invocation: java DemoBoxLayout Enable struts and springs demo c e Launch Resize Resize more Springs Struts (10 pixels) 19

Size Control How is a component s size determined during layout and during resize operations? Three factor determining component sizes: The component s size properties (preferred, minimum, and maximum) Whether the size properties are assumed or explicitly set Layout manager policies Example Program DemoSizeControl.java usage: java DemoSizeControl arg1 where 'arg1' specifies the layout manager as follows: 1 = BorderLayout 2 = FlowLayout 3 = GridLayout 4 = BoxLayout Example (next 2 slides) 20

Example Program (2) Component construction and configuration JButton b1 = new JButton("Button One"); JButton b2 = new JButton("B2"); JButton b3 = new JButton("B3"); JButton b4 = new JButton("B4"); b3.setmaximumsize(b1.getpreferredsize()); b4.setpreferredsize(new Dimension(150, 50)); b4.setmaximumsize(new Dimension(150, 50)); BorderLayout FlowLayout GridLayout BoxLayout Expands to maximum size when resizing 21

Default Layout Managers JPanel = FlowLayout JFrame s content pane = BorderLayout Programming Challenge Create a GUI layout, as follows Name the program PC_LayoutExample.java Upon launching After resizing 22

Next Topic 23