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

Slides:



Advertisements
Similar presentations
Layouts and Graphics. component - container - layout Un Container contiene [0 o +] Components Il Layout specifica come i Components sono disposti nel.
Advertisements

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.
CE203 - Application Programming Autumn 2013CE203 Part 71 Part 7.
Graphical User Interfaces
Graphical User Interfaces Java’s AWT and Swing APIs.
TCU CoSc Programming with Java Visual Design (Chapter 5)
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.
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.
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.
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.
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.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
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.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
1 Java Swing Layout Management. 2 Laying out components Manage realized components Manage realized components Determine size and position Determine size.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Layout Manager Summary
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
3461 Laying Out Components Interior Design for GUIs.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
MIT AITI 2003 Lecture 16. Swing Part I Let’s swing and have some fun !!!
Basics of GUI Programming Chapter 11 and Chapter 22.
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.
AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
CSI 3125, Preliminaries, page 1 Layout Managers. CSI 3125, Preliminaries, page 2 Layout Managers The LayoutManagers are used to arrange components in.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Java Layouts CSIS 3701: Advanced Object Oriented Programming.
Java Swing - Lecture 3 Layout Management
Graphical User Interface (GUI)
User Interface Components. Layout Placement of UI components in a window – Size & Position Each component occupies a rectangular region in the window.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
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.
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
Module 13: Swing API Object Oriented Programming(Java)
Chapter 7 A First Look at GUI Applications Layout Managers.
Swing JComponents.
Modern Programming Language Java
University of Central Florida COP 3330 Object Oriented Programming
Tim McKenna Layout Mangers in Java Tim McKenna
Containers and Components
תכנות מכוון עצמים בשפת JAVA
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Panels & Layout Managers
Chapter 7-3 (Book Chapter 14)
Steps to Creating a GUI Interface
GUI Layouts By: Leonard & Saif.
Layout Organization and Management
Presentation transcript:

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

G5BUID - Java Swing Layout managers – general aspects Creating a layout manager Consulting managers Types of managers Choosing managers Other features of component layout All Covered very well here:

G5BUID - Java Swing Creating a layout manager Default layout managers JFrame, JDialog, JApplet have BorderLayout JPanel has FlowLayout Except when used as a Content Pane (Border Layout) Setting the layout manager for a container JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout());

G5BUID - Java Swing Consulting layout managers (1) Consulted automatically when container may need to change its appearance. These methods result in consultation, but DONT trigger new layout add(), remove(), removeAll() getAlignmentX(), getAlignmentY() getPreferredSize(), getMinimumSize(), getMaximumSize()

G5BUID - Java Swing Consulting layout managers (2) These methods actually result in the manager performing layout. JFrame.pack(); Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. JFrame.show() & JFrame.setVisible(true); Shows the component JComponent.revalidate(); This method will automatically be called on this component when a property value changes. Looks for all dependent components and calls validate() on them. Validate() causes a container to lay out its subcomponents again

G5BUID - Java Swing Layout managers - types BorderLayout BoxLayout FlowLayout GridLayout GridBagLayout CardLayout

G5BUID - Java Swing BorderLayout Five areas NORTH, SOUTH, EAST, WEST and CENTER Not all areas must be used Do not assume a default area for components Centre gets as much area as possible Specify location as argument of add method pane.setLayout(new BorderLayout()); pane.add(new JButton(Button 1 (NORTH)), BorderLayout.NORTH); Setting gaps between components (default = 0) BorderLayout.setHgap(int gap); BorderLayout.setVgap(int gap); BorderLayout(int horizontalGap, int verticalGap) - Constructor

G5BUID - Java Swing BoxLayout (1) Components on top / next to each other Direction is your choice Tries to size components at preferred height for Y_AXIS or width for X_AXIS Width as largest component width See above picture

G5BUID - Java Swing FlowLayout Very simple - JPanels default Components in row(s) At preferred size Alignment FlowLayout.LEFT FlowLayout.CENTRE FlowLayout.RIGHT Gaps Default = 5 Specifying - setter hGap vGap methods or via constructor

G5BUID - Java Swing GridLayout Grid of cells - all same size Components take all space in a cell Gaps default = 5 use setter methods hGap and vGap or via arguments to constructor Re-sizing Cells resize to be as large as possible in given window / container