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

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

Laying Out Components. What is Widget Layout?

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

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

Dr. Hikmat A. M. AbdelJaber

Output in Window Systems and Toolkits

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

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

Layout. Dynamic layout Layout design pattern Layout strategies

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

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!

BASICS OF GRAPHICAL APPS

CS 251 Intermediate Programming GUIs: Components and Layout

Containers and Components

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

Introduction to the JAVA UI classes Advanced HCI IAT351

Graphical User Interface (GUI)

Graphical User Interface (GUI)

YouTube Break.

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

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

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

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

Basicsof. JavaGUI and SWING

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

UI Software Organization

The MVC Design Pattern

Intermediate Microsoft Word 2010

No SVN checkout today. Object-Oriented Design

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

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

- learnability. - efficiency. - graphic design

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

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

Tips and Techniques for Designing the Perfect Layout with SAS Visual Analytics

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

Lesson 2: First Java Programs

Graphical User Interfaces. Comp 152

Sri Vidya College of Engineering & Technology

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

Creating Professional Swing UIs Using the NetBeans GUI Builder

Table Basics. The structure of an table

Chapter 2 First Java Programs

Window Interfaces Using Swing Objects

Object Oriented Design & Patterns. Part 1

GUI Components: Part 1

How to Images. Upload images into your account via the Images panel. Once uploaded, your images are ready to drag and drop into your .

Lecture 5: Java Graphics

CSC Website Design, Spring CSS Flexible Box

2IS45 Programming

Object-Oriented Programming

More Swing. Chapter 14. Chapter 14 1

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

CS 2113 Software Engineering

GUI in Java TalentHome Solutions

CSC207H: Software Design Lecture 11

Dreamweaver Tutorials Working with Tables

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

CS11 Java. Fall Lecture 4

5. In JAVA, is exception handling implicit or explicit or both. Explain with the help of example java programs. [16]

Java Programming Lecture 6

CS11 Java. Fall Lecture 3

WORD Creating Objects: Tables, Charts and More

User interfaces and Swing

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

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

Unit 6: Graphical User Interface

Lesson 15 Working with Tables

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

GUI Programming. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies

Using Adobe Contribute 4 A guide for new website authors

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Eclipse Scout. Release Notes. Scout Team. Version 7.1

Lesson 15 Working with Tables

9 Introducing Drag and Drop Techniques

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

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

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

Java. GUI building with the AWT

Window Interfaces Using Swing Objects

Reference Services Division Presents. Microsoft Word 2

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

Tcl/Tk lecture. What is the Wish Interpreter? CIS 410/510 User Interface Programming

CSV Roll Documentation

Using Microsoft Word. Working With Objects

Unit 1: Working With Tables

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

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

Lesson #6: Basic Transformations with the Absolute Value Function

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Exercises Lecture 3 Layouts and widgets

1 Using the NetBeans IDE

Common Image Sizes for Templates

A GUI-Builder Approach to grid Graphics

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

Centricity 2.0 Section Editor Help Card

Part I: Learn Common Graphics Components

Transcription:

COSC User Interfaces Module 5 Laying Out Components 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 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 s DemoSizeProperties.java DemoSize.java DemoPosition.java 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) Widget Layout Models Absolute (a.k.a. fixed) Control for component size and position Various Layout Managers 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) Absolute Positioning (3) 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 A lot of work to do in ComponentListener DemoAbsolute.java Struts and Springs Idea Use constraints to define geometric relationships between widgets Goals Easy to use Handles window resizing appropriately and automatically

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 (preferred size, minimum size, maximum size) During layout, components report their size properties to the layout manager (recursively, following the containment hierarchy) Designers have limited control over this Some layout managers respect size properties, while others do not Mechanics of Window Resizing 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? Widget Communication: (Subclassing and Parent Notification) Widget Communication 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 super class are overridden to handle updating the widget as well as notifying other widgets This is a useful technique to use in our programs too 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 GridBagLayout SpringLayout 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: Supports Preferred Size only Components expand to fill space in region

Border Layout (2) Components expand (or stretch ) to fill space as follows North Expand direction Demo.java usage: java Demo 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 Demo 0 Invocation: java Demo 10 Resize Resize Variable intrinsic size Struts

Java s Layout Managers GridBagLayout SpringLayout 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: Supports Preferred Size only Component size is fixed Space is added before / after / below the entire group of components to fill available space Demo.java usage: java Demo arg1 arg2 (2) Default for struts : hgap = vgap = 5, alignment = center Invocation: java Demo 5 c where 'arg1' = strut size in pixels and 'arg2' is one of c = center alignment l = left alignment r = right alignment Resize Example (next 2 slides) Fill available space before/after/below group of components

Resize (3) With struts : hgap = vgap = 10, alignment = right Invocation: java Demo 10 r Java s Layout Managers GridBagLayout SpringLayout 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 Supports Preferred Size only Components expand to fill rectangle Demo.java usage: java Demo arg1 where 'arg1' = strut size in pixels Example (next 2 slides)

(2) (3) No struts With struts : hgap = vgap = 10 Invocation: java Demo 0 Invocation: java Demo 10 Resize Resize Equal-size rectangles Java s Layout Managers GridBagLayout SpringLayout 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 ( ) Supports all three intrinsic sizes: Preferred, Minimum and Maximum Works best will all three properties set

Demo.java usage: java Demo arg1 arg2 where 'arg1' is one of c = centre alignment l = left alignment r = right alignment (2) Invocation: java Demo l d Invocation: java Demo r d Invocation: java Demo c d and 'arg2' is one of e = enable struts and springs demo d = disable struts and springs demo Example (next 2 slides) Default is left align (3) Enable struts and springs demo Invocation: java Demo c e Resize Resize more Size Control How is a component s size determined during layout and during resize operations? Springs Struts (10 pixels) 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 = 2 = 3 = 4 = (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)); Example (next 2 slides) To be continued Expands to maximum size when resizing