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

Similar documents
Laying Out Components. What is Widget Layout?

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

CS 251 Intermediate Programming GUIs: Components and Layout

Containers and Components

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

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

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

Dr. Hikmat A. M. AbdelJaber

Output in Window Systems and Toolkits

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

Layout. Dynamic layout Layout design pattern Layout strategies

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

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

No SVN checkout today. Object-Oriented Design

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

Introduction to the JAVA UI classes Advanced HCI IAT351

BASICS OF GRAPHICAL APPS

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

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

Object Oriented Design & Patterns. Part 1

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

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

YouTube Break.

Graphical User Interface (GUI)

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

Sri Vidya College of Engineering & Technology

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

Basicsof. JavaGUI and SWING

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

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

Chapter 2 First Java Programs

More Swing. Chapter 14. Chapter 14 1

Top-Level Containers

Unit 6: Graphical User Interface

CSC207H: Software Design Lecture 11

GUI in Java TalentHome Solutions

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

Graphical User Interfaces. Comp 152

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

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

Java Programming Lecture 6

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

CS 2113 Software Engineering

Graphical User Interface (GUI)

- learnability. - efficiency. - graphic design

Lesson 2: First Java Programs

Window Interfaces Using Swing Objects

Part I: Learn Common Graphics Components

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

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

Chapter 14. More Swing

Graphical User Interfaces (GUIs)

Lecture 5: Java Graphics

2IS45 Programming

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

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

Building Graphical User Interfaces. GUI Principles

Java. GUI building with the AWT

PIC 20A GUI with swing

CS11 Java. Fall Lecture 4

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

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

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

Dell Canvas Layout. Version 1.0 User s Guide

CS11 Java. Fall Lecture 3

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

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

Chapter 12 Advanced GUIs and Graphics

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

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

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

Graphical User Interfaces in Java

Graphic User Interfaces. - GUI concepts - Swing - AWT

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

Window Interfaces Using Swing Objects

Human-Computer Interaction IS4300

Lecture 18 Java Graphics and GUIs

The AWT Package, An Overview

Building Graphical User Interfaces. Overview

CSCI 201L Midterm Written SOLUTION Fall % of course grade

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

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

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

Object-Oriented Programming

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

CSE 331 Software Design & Implementation

Window Interfaces Using Swing. Chapter 12

encompass a group of features for building Graphical User Interfaces (GUI).

Summary Chapter 25 GUI Components: Part 2

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

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).

Programming Mobile Devices J2SE GUI

More UI Output Tasks: Damage Management & Layout

The MVC Design Pattern

Transcription:

What is Widget Layout? Laying Out Components 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? Interior Design for GUIs Example Resizing a Window Menu wraps Hierarchical Widget Layout Widgets are arranged hierarchically, relative to the parent (recall containment hierarchy) Buttons lost Scrollbar added

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) s DemoSizeProperties.java DemoSize.java DemoPosition.java Programming 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

Widget Layout Models Absolute (a.k.a. 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) 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 DemoAbsolute.java

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 Text Field Button Advantage When the window is resized, widget position is determined automatically by constraint equations 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

Subclassing Most widgets are subclasses of other widgets Methods in the 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) 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

Border Layout (2) Components expand (or stretch ) to fill space as follows North Expand direction DemoBorderLayout.java usage: java DemoBorderLayout arg1 where 'arg1' = strut size in pixels West Center East South Example (next 2 slides) No struts With struts : hgap = vgap = 10 pixels Invocation: java DemoBorderLayout 0 Invocation: java DemoBorderLayout 10 Variable intrinsic size Struts

FlowLayout Arranges components in a group, left-to-right 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 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) (2) Default for FlowLayout struts : hgap = vgap = 5, alignment = center (3) With struts : hgap = vgap = 10, alignment = right Invocation: java DemoFlowLayout 5 c Invocation: java DemoFlowLayout 10 r Fill available space before/after/below group of components

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 DemoGridLayout.java usage: java DemoGridLayout arg1 where 'arg1' = strut size in pixels Example (next 2 slides) (2) No struts (3) With struts : hgap = vgap = 10 Invocation: java DemoGridLayout 0 Invocation: java DemoGridLayout 10 Equal-size rectangles

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 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) (2) Invocation: java DemoBoxLayout l d Invocation: java DemoBoxLayout r d Invocation: java DemoBoxLayout c d (3) Enable struts and springs demo Invocation: java DemoBoxLayout c e more Springs Default is left align Struts (10 pixels)

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 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) (2) Component construction and configuration BorderLayout FlowLayout 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()); GridLayout b4.setpreferredsize(new Dimension(150, 50)); b4.setmaximumsize(new Dimension(150, 50)); BoxLayout Expands to maximum size when resizing

Default Layout Managers JPanel = FlowLayout JFrame s content pane = BorderLayout Programming Challenge Create a GUI layout, as follows Name the program PC_LayoutExample.java Enter some text: Hello there Enter some text: Hello there Upon launching After resizing Clear Exit Clear Exit Solution PC_LayoutExample.java Next Topic