Layout Manager Summary

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.
Graphical User Interfaces
Java Software Development Paradigm Lecture # 12. Basics of GUI.
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
Introduction to JFC Swing Written by Adam Carmi. Agenda About JFC and Swing Pluggable Look and Feel Swing Components Borders Layout Management Events.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 28 Containers, Layout.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
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.
Jan Containers Yangjun Chen Dept. Business Computing University of Winnipeg.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
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.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Introduction to Computation and Problem Solving Class 15: Constructing Interfaces with Swing Prof. Steven R. Lerman and Dr. V. Judson Harward 1.
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.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Introducing the Eclipse Visual Editor David Gallardo.
Field Trip #19 Animations with Java By Keith Lynn.
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.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
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.
CPSC 233 Tutorial Xin Apr 6, Reading files An example available on my website pages.cpsc.ucalgary.ca/~liuxin.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 14 : Swing II King Fahd University of Petroleum & Minerals College of Computer Science.
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.
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.
Lab 4: GUIs, Panels, Mouse and Key Listeners ICOM4015: FALL 2014 A N I NTRODUCTION TO P ANELS AND L AYOUTS CREATED BY KATYA I. BORGOS REVISED BY AMIR H.
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
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.
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.
Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface.
Module 13: Swing API Object Oriented Programming(Java)
Chapter 7 A First Look at GUI Applications Layout Managers.
Object-Oriented Software Engineering JFrames with Swing.
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
Panels & Layout Managers
Graphical User Interface
Steps to Creating a GUI Interface
GUI Layouts By: Leonard & Saif.
Layout Organization and Management
Presentation transcript:

Layout Manager Summary

Layout Managers BorderLayout BoxLayout CardLayout FlowLayout GridBagLayout GridLayout SpringLayout

BorderLayout a BorderLayout has five areas. These areas are specified by the BorderLayout constants PAGE_START, PAGE_END, LINE_START, LINE_END, and CENTER. (Previously NORTH, SOUTH, EAST, WEST and CENTER)

BoxLayout The BoxLayout class puts components in a single row or column. It respects the components' requested maximum sizes and also lets you align components

CardLayout The CardLayout class lets you implement an area that contains different components at different times. A CardLayout is often controlled by a combo box, with the state of the combo box determining which panel (group of components) the CardLayout displays.

FlowLayout FlowLayout is the default layout manager for every JPanel. It simply lays out components in a single row, starting a new row if its container isn't sufficiently wide.

GridBagLayout GridBagLayout is a sophisticated, flexible layout manager. It aligns components by placing them within a grid of cells, allowing some components to span more than one cell. The rows in the grid can have different heights, and grid columns can have different widths.

GridLayout GridLayout simply makes a bunch of components equal in size and displays them in the requested number of rows and columns

Using Layout Managers A layout manager is an object that implements the LayoutManager interface and determines the size and position of the components within a container. Setting the Layout Manager Adding Components to a Container Providing Size and Alignment Hints Putting Space Between Components Setting the Container's Orientation

SpringLayout SpringLayout is a flexible layout manager designed for use by GUI builders. It lets you specify precise relationships between the edges of components under its control. For example, you might define that the left edge of one component is a certain distance (which can be dynamically calculated) from the right edge of a second component.

Setting the Layout Manager the only containers whose layout managers you need to worry about are JPanels and content panes. Each JPanel object is initialized to use a FlowLayout, unless you specify differently when creating the JPanel. Content panes use BorderLayout by default. If you don't like the default layout manager that a panel or content pane uses, you're free to change it to a different one. To set a panel's layout manager using the JPanel constructor. JPanel panel = new JPanel(new BorderLayout()); After a container has been created, you can set its layout manager using the setLayout method. Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout());

Adding Components to a Container When you add components to a panel or content pane, the arguments you specify to the add method depend on the layout manager that the panel or content pane is using. For example, BorderLayout requires that you specify the area to which the component should be added pane.add(aComponent, BorderLayout.PAGE_START);

Providing Size and Alignment hints specifying one or more of the minimum, preferred, and maximum sizes of the component. setMinimumSize, setPreferredSize, and setMaximumSize. Or you can create a subclass of the component that overrides the appropriate getter methods — getMinimumSize, getPreferredSize, and getMaximumSize. Here is an example of making a component's maximum size unlimited: component.setMaximumSize( new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); Many layout managers don't pay attention to a component's requested maximum size. However, BoxLayout and SpringLayout do. You set alignment hints either by invoking the component's setAlignmentX and setAlignmentY methods, or by overriding the component's getAlignmentX and getAlignmentY methods. Although most layout managers ignore alignment hints, BoxLayout honors them.

Putting Space Between Components Three factors influence the amount of space between visible components in a container: The layout manager Some layout managers automatically put space between components; others don't. Some let you specify the amount of space between components. Invisible components You can create lightweight components that perform no painting, but that can take up space in the GUI. Often, you use invisible components in containers controlled by BoxLayout. Empty borders No matter what the layout manager, you can affect the apparent amount of space between components by adding empty borders to components, such as panels and labels.

Setting the Container’s Orientation The componentOrientation property provides a way of indicating that a particular component should use something different from the default left-to-right, top-to-bottom orientation. To set a container's orientation, you can use either the Component-defined method setComponentOrientation or, to set the orientation on the container's children as well, applyComponentOrientation. The argument to either method can be a constant such as: ComponentOrientation.RIGHT_TO_LEFT, or it can be a call to the ComponentOrientation method getOrientation(Locale). For example, the following code causes all JComponents to be initialized with an Arabic-language locale, and then sets the orientation of the content pane and all components inside it accordingly: JComponent.setDefaultLocale(new Locale("ar")); JFrame frame = new JFrame(); ... Container contentPane = frame.getContentPane(); contentPane.applyComponentOrientation( ComponentOrientation.getOrientation(contentPane.getLocale())); The standard layout managers that support component orientation are FlowLayout, BorderLayout, BoxLayout, GridBagLayout, and GridLayout.

Setting the Container’s Orientation Default left-to-right right-to-left

Setting event (summary) See next page