Laying Out Components Interior Design for GUIs. Nov 042 What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame’s.

Slides:



Advertisements
Similar presentations
G5BUID - Java Swing Laying out components Manage realized components Determine size and position Each container has a layout manager (usually)
Advertisements

Introduction to Java 2 Programming
Introduction to Swing Components Chapter 14. Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
Unit 121 A layout manager is an object that determines the manner in which components are arranged in a container. Each layout manager implements one of.
TCU CoSc Programming with Java Visual Design (Chapter 5)
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Corresponds with Chapter 12
CS221 © 2007 Ray S. Babcock Layout, Components, & Data Entry Appendix C.3-C.5.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
GUI programming AWT(Abstract Windows Toolkit)-GUI components library when Java was introduced AWT was replaced by Swing components import javax.swing.*;
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
1 L48 Advanced GUI Component (3). 2 OBJECTIVES  To use additional layout managers.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
GUI Layout Managers Arkadiusz Edward Komenda. Outline Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers.
GUI and event-driven programming An introduction.
Java Programming Chapter 10 Graphical User Interfaces.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Layout Managers A layout manager is an object that determines the way that components are arranged in a container There are several predefined layout managers.
MSc Workshop - © S. Kamin, U.Reddy Lect 5 – GUI Prog - 1 Lecture 5 – GUI Programming r Inner classes  this and super r Layout r Reading: m.
Nov 061 Size Control How is a component’s size determined during layout and during resize operations? Three factors determine component sizes: The component’s.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Chapter 8: Getting Started with Graphics Programming Graphics Class Hierarchy Graphics Class Hierarchy Frames Frames The relationship between frame and.
Introducing the Eclipse Visual Editor David Gallardo.
GUI development in Java L. Grewe Two methodologies for things to appear on the screen 1. By painting / drawing e.g. drawing an Image e.g. drawing an.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Layout Manager Summary
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
Object-Oriented Software Engineering
3461 Laying Out Components Interior Design for GUIs.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Computer Science 209 GUIs Model/View/Controller Layouts.
CPSC 233 Tutorial Xin Apr 6, Reading files An example available on my website pages.cpsc.ucalgary.ca/~liuxin.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Graphical User Interfaces Tonga Institute of Higher Education.
AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 3 Designing the Interface with Layout Managers.
 Many event-listener interfaces contain multiple methods.  An adapter class implements an interface and provides a default implementation (with an empty.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Java Layouts CSIS 3701: Advanced Object Oriented Programming.
Java Swing - Lecture 3 Layout Management
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
User Interface Components. Layout Placement of UI components in a window – Size & Position Each component occupies a rectangular region in the window.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
Chapter 7 A First Look at GUI Applications Layout Managers.
Java FX: Scene Builder.
Modern Programming Language Java
University of Central Florida COP 3330 Object Oriented Programming
Tim McKenna Layout Mangers in Java Tim McKenna
Layout Managers A layout manager is an object that determines the way that components are arranged in a container There are several predefined layout managers.
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Layout Organization and Management
Presentation transcript:

Laying Out Components Interior Design for GUIs

Nov 042 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

Nov 043 Resizing a Window Menu wraps Buttons lost Scrollbar added

Nov 044 Hierarchical Widget Layout Widgets are arranged hierarchically, relative to the parent (recall containment hierarchy)

Nov 045 Hierarchical Layout (2)

Nov 046 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)

Nov 047 Example Program DemoSizeProperties.java DemoSize.java DemoPosition.java

Nov 048 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

Nov 049 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

Nov 0410 Absolute Positioning Component position and size explicitly specified… X and Y screen coordinates Width and height of component Units: pixels (typically)

Nov 0411 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

Nov 0412 Example Program DemoAbsolute.java

Nov 0413 Struts and Springs Goals Easy to use Handles window resizing appropriately Idea Add constraints to define geometric relationships between widgets

Nov 0414 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 Text FieldButton

Nov 0415 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!

Nov 0416 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 responses to an implicit event (the reaction of one widget to another) Accomplished by subclassing or parent notification

Nov 0417 Subclassing Most widgets are subclasses of other widgets Methods in superclass are overridden to handle updating the widget as well as notifying other widgets Disadvantages: Large number of unique widget classes Actions for entire window scattered throughout the code

Nov 0418 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)

Nov 0419 Java’s Layout Managers BorderLayout FlowLayout GridLayout BoxLayout GridBagLayout CardLayout OverlayLayout etc.

Nov 0420 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

Nov 0421 Border Layout (2) Components ‘expand’ (or ‘stretch’) to fill space as follows North South West EastCenter Expand direction

Nov 0422 Example Program DemoBorderLayout.java usage: java DemoBorderLayout arg1 where 'arg1' = strut size in pixels Example (next 2 slides)

Nov 0423 Example Program LaunchResize Invocation: java DemoBorderLayout 0 No struts Variable intrinsic size

Nov 0424 Example Program LaunchResize With struts : hgap = vgap = 10 pixels Invocation: java DemoBorderLayout 10 Struts

Nov 0425 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

Nov 0426 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)

Nov 0427 Example Program (2) Launch Resize Default for FlowLayout… struts : hgap = vgap = 5, alignment = center Invocation: java DemoFlowLayout 5 c Fill available space before/after/below group of components

Nov 0428 Example Program (3) Launch Resize Invocation: java DemoFlowLayout 10 r With struts : hgap = vgap = 10, alignment = right

Nov 0429 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

Nov 0430 Example Program DemoGridLayout.java usage: java DemoGridLayout arg1 where 'arg1' = strut size in pixels Example (next 2 slides)

Nov 0431 Example Program (2) LaunchResize Invocation: java DemoGridLayout 0 No struts Equal-size rectangles

Nov 0432 Example Program (3) LaunchResize Invocation: java DemoGridLayout 10 With struts : hgap = vgap = 10

Nov 0433 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

Nov 0434 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)

Nov 0435 Example Program (2) Invocation: java DemoBoxLayout r d Invocation: java DemoBoxLayout l d Invocation: java DemoBoxLayout c d Default is left align

Nov 0436 Example Program (3) Invocation: java DemoBoxLayout c e LaunchResizeResize more Struts (10 pixels) Springs Enable struts and springs demo