University of Central Florida COP 3330 Object Oriented Programming

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

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.
GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
Graphical User Interfaces
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.
Advanced Swing. Advanced Layout Managers GridBagLayout – Example: Web Browser (Grid Bag Layout)Web Browser (Grid Bag Layout) BoxLayout – Example: Web.
Corresponds with Chapter 12
LayoutManager, J 1 Layout Manager. LayoutManager, J 2 Layout Manager To each UI container there is a layout manager (an object). When you add a component.
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.
LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager.
1 L48 Advanced GUI Component (3). 2 OBJECTIVES  To use additional layout managers.
Jan Containers Yangjun Chen Dept. Business Computing University of Winnipeg.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng 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.
1 Chapter 22 Containers, Layout Managers, and Borders.
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.
©2007 · Georges Merx and Ronald J. NormanSlide 1 Chapter 7 Interfacing with Users.
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.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
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.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management Brad Myers Advanced User Interface Software 1© 2013.
Layout Managers Arranges and lays out the GUI components on a container.
Layout Manager Summary
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
© Marty Hall, Larry Brown, Web core programming 1 Layout Managers Arranging Elements in Windows.
Layout Managers CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
University of Limerick1 Software Architecture Java Layout Managers.
Object-Oriented Software Engineering
3461 Laying Out Components Interior Design for GUIs.
Copyright Curt Hill GridBag Layout Manager A flexible but complicated layout.
Grid Bag Layout Most Complex and Powerful Components can vary in size and can be added in any order Draw out on piece of paper first Columns and Rows:
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.
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.
CSI 3125, Preliminaries, page 1 Layout Managers. CSI 3125, Preliminaries, page 2 Layout Managers The LayoutManagers are used to arrange components in.
Java Layouts CSIS 3701: Advanced Object Oriented Programming.
Java Swing - Lecture 3 Layout Management
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.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Session 10. Java Simplified / Session 10 / 2 of 36  An Applet is a Java program that can be executed with the help of a Java enabled browser.  Every.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
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.
Object-Oriented Software Engineering JFrames with Swing.
Chapter 5 Patterns and GUI Programming -Part 2-. STRATEGY Pattern Layout Managers What if we need to specifies pixel position of components when  User.
Java FX: Scene Builder.
Graphical User Interfaces -- GUIs
Swing JComponents.
Modern Programming Language Java
Tim McKenna Layout Mangers in Java Tim McKenna
Chap 7. Building Java Graphical User Interfaces
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
Panels & Layout Managers
Chapter 33 Containers, Layout Managers, and Borders
LayoutManagers The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes.
GUI Layouts By: Leonard & Saif.
Layout Organization and Management
Presentation transcript:

University of Central Florida COP 3330 Object Oriented Programming

Agenda Administrative Layout managers

Layout managers

Layout Managers BorderLayout BoxLayout CardLayout FlowLayout GridBagLayout GridLayout GroupLayout SpringLayout

Layout Managers BorderLayout Default for the content pane of JFrame, JDialog, and JApplet Arranges the components into five areas (before JDK release 1.4, the preferred names for the various areas were based on points of the compass) NORTH SOUTH EAST WEST CENTER Also known as (now the preferred standard because they enable programs to adjust to languages that have different orientations) PAGE_START PAGE_END LINE_START LINE_END

Layout Managers BoxLayout Puts components in a single row or column It respects the components' requested maximum sizes Lets you align components

Layout Managers CardLayout Lets you implement an area that contains different components at different times Often controlled by a combo box, with the state of the combo box determining which panel (group of components) to display An alternative to using CardLayout is using a tabbed pane, which provides similar functionality but with a pre-defined GUI

Layout Managers FlowLayout Default for javax.swing.JPanel  Lays out components in a single row Starting a new row if its container is not sufficiently wide Places components sequentially left to right in the order they were added Order can be specified if desired

GridBagLayout GridBagLayout One of the most flexible layout managers One of the most complex layout managers Places components in a grid of rows and columns (i.e. cells) Allows for specified components to span multiple rows or columns Not all rows necessarily have the same height Similarly, not all columns necessarily have the same width Uses the components' preferred sizes to determine how big the cells should be.

GridBagLayout 1 2 3 gridx (column) 1 2 3 gridy (row)

GridBagLayout GridBagLayout The grid has three rows and three columns The button in the second row spans all the columns The button in the third row spans the two right columns

GridBagConstraints GridBagConstraints The way the program specifies the size and position characteristics of its components Specifying constraints for each component The preferred approach to set constraints on a component is to use the Container.add variant, passing it a GridBagConstraints object

GridBagConstraints JPanel pane = new JPanel(new GridBagLayout()); OR pane.setLayout(new GridBagLayout()); GridBagLayout gridBagLayout = new GridBagLayout(); pane.setLayout(gridBagLayout); GridBagConstraints c = new GridBagConstraints(); pane.add(theComponent, c);

GridBagConstraints // X is the column // Y is the row // W is the width in cells // H is the height in cells // aContainer is the container the component is added to // aComponent is the component being added to the container private void addComponent( int x, int y, int w, int h, Container aContainer, Component aComponent ) { constraints.gridx = x; constraints.gridy = y; constraints.gridwidth = w; constraints.gridheight = h; gridBagLayout.setConstraints( aComponent, constraints ); aContainer.add( aComponent ); }

GridBagConstraints // X is the column // Y is the row // W is the width in cells // H is the height in cells // aContainer is the container the component is added to // aComponent is the component being added to the container this.addComponent(0, 1, 1, 1, dataPane, fromDestLbl);

GridBagConstraints Instance variables gridx - Specifies the cell containing the leading edge of the component's display area, where the first cell in a row has gridx=0 gridy - Specifies the cell at the top of the component's display area, where the topmost cell has gridy=0. gridwidth - Specifies the number of cells in a row for the component's display area. gridheight - Specifies the number of cells in a column for the component's display area. weightx - Specifies how to distribute extra horizontal space. weighty - Specifies how to distribute extra vertical space.

GridBagConstraints Instance variables anchor - This field is used when the component is smaller than its display area. fill - This field is used when the component's display area is larger than the component's requested size. insets - This field specifies the external padding of the component, the minimum amount of space between the component and the edges of its display area. ipadx - This field specifies the internal padding of the component, how much space to add to the minimum width of the component. ipady - This field specifies the internal padding, that is, how much space to add to the minimum height of the component.

Layout Managers GridLayout Arranges the components into rows and columns Components equal in size and displays them in the requested number of rows and columns

Layout Managers GroupLayout Developed for use by GUI builder tools Can also be used manually Works with the horizontal and vertical layouts separately; layout is defined for each dimension independently However, each component needs to be defined twice in the layout

Layout Managers SpringLayout A flexible layout manager designed for use by GUI builders Specify precise relationships between the edges of components under its control Lays out the children of its associated container according to a set of constraints  Very low-level Really should only use it with a GUI builder

UpperSectionUi ~ JPanel GameUi ~ JPanel Jframe ~ YahtzeeUi ScoreCare UI ~ JPanel rightPanel ~ JPanel UpperSectionUi ~ JPanel GameUi ~ JPanel PlayerUi ~ JPanel LowerSectionUi ~ JPanel RollUi ~ JPanel grandTotal ~ JLabel