Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.

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
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.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
GUI programming AWT(Abstract Windows Toolkit)-GUI components library when Java was introduced AWT was replaced by Swing components import javax.swing.*;
1 GUI Programming (Part III). Graphical User Interfaces (Part III) Overview  GUI Programming Issues.  GUI Programming in Java: Then and Now.  Overview.
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Layout Management Containers can arrange their components. Our container is a JPanel, and it can set the way it’s components will be laid out : mypanel.setLayout.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
1 Why layout managers Can we perform layout without them? –Yes. A container’s layout property can be set to null. Absolute positioning: specify size and.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
JFrame and JPanel CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
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.
MIT-AITI 2004 – Lecture 16 Introduction to Swing.
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.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
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.
Computer Science 209 GUIs Model/View/Controller Layouts.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
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.
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.
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.
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.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Chapter 7 A First Look at GUI Applications Layout Managers.
Graphical User Interfaces
Graphical User Interfaces -- GUIs
Swing JComponents.
GUIs Model/View/Controller Layouts
Modern Programming Language Java
Java GUI.
University of Central Florida COP 3330 Object Oriented Programming
Tim McKenna Layout Mangers in Java Tim McKenna
Chapter 13: Advanced GUIs and Graphics
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Graphical User Interface
LayoutManagers The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes.
Layout Organization and Management
Graphical User Interface
Presentation transcript:

Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other layout managers to build good GUI applications. Introduction FlowLayout Manager GridLayout Manager Self-check Exercise 1 BorderLayout Manager Self-check Exercise 2 Exercises

Unit 132 Introduction to GUI Layout Managers A layout manager determines the placement of components with a container. Each container has a default layout manager. A new layout manager can be installed using the setLayout method. Each layout manager implements one of the two interfaces: LayoutManger or LayoutManger2. Here are some common standard layout managers of Java: oFlowLayout oGridLayout oBorderLayout oGridBagLayout

Unit 133 Introduction to Flow Layout FlowLayout places components sequentially from left to right in the order added. Components placement depends on the current size of the container. When the container is resized the components are automatically resized. FlowLayout is the default layout for panels. FlowLayout has three constructors: oFlowLayout() oFlowLayout(int align) oFlowLayout(int align, int hgap, int vgap)

Unit 134 Example 1: Flow Layout Test import javax.swing.*; import java.awt.*; class TestFlowLayout extends JFrame{ public TestFlowLayout(){ Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(new JButton("1")); cp.add(new JButton("2")); cp.add(new JButton("3")); cp.add(new JButton("4")); cp.add(new JButton("5")); cp.add(new JButton("6")); cp.add(new JButton("7")); setSize(300,300); setTitle("Flow Layout Test1"); setVisible(true); } public static void main(String [] args){ new TestFlowLayout(); } }

Unit 135 Introduction to Grid Layout GridLayout places components in a rectangular grid. GridLayout is good for laying out containers that look like grids. GridLayout forces occupation of all available container space. GridLayout has three constructors: oGridLayout() oGridLayout(int rows, int cols) oGridLayout(int rows, int cols, int hgap, int vgap)

Unit 136 Example 2: Grid Layout Test import javax.swing.*; import java.awt.*; class TestGridLayout extends JFrame{ public TestGridLayout(){ Container cp = getContentPane(); cp.setLayout(new GridLayout(3,3)); cp.add(new JButton("1")); cp.add(new JButton("2")); cp.add(new JButton("9")); cp.add(new JButton("4")); cp.add(new JButton("5")); cp.add(new JButton("6")); cp.add(new JButton("7")); cp.add(new JButton("8")); cp.add(new JButton("3")); setSize(300,300); setVisible(true); } public static void main(String [] args){ new TestGridLayout(); }

Unit 137 Example 2: Another Grid Layout Test import javax.swing.*; import java.awt.*; class TestGridLayout extends JFrame{ public TestGridLayout(){ Container cp = getContentPane(); cp.setLayout(new GridLayout(3,3)); cp.add(new JButton("1")); cp.add(new JButton("2")); cp.add(new JButton("9")); cp.add(new JButton("4")); cp.add(new JButton("5")); cp.add(new JButton("6")); cp.add(new JButton("7")); cp.add(new JButton("8")); setSize(300,300); setVisible(true); } public static void main(String [] args){ new TestGridLayout(); }

Unit 138 Introduction to Border Layout BorderLayout places components according to five areas: "North", "South", "East", "West" and "Center". When you enlarge a container the center area grabs as much of the new space as possible. BorderLayout is good for maintaining a row of buttons in one of the areas near the edgees. BorderLayout has two constructors: oBorderLayout() oBorderLayout(int hgap, int vgap)

Unit 139 Example 3: Border Layout Test import javax.swing.*; import java.awt.*; class TestBorderLayout extends JFrame{ JPanel jb = new JPanel(); public TestBorderLayout(){ jb.setLayout(new GridLayout(3,3)); jb.add(new JButton("1")); jb.add(new JButton("2")); jb.add(new JButton("3")); jb.add(new JButton("4")); jb.add(new JButton("5")); jb.add(new JButton("6")); jb.add(new JButton("7")); jb.add(new JButton("8")); jb.add(new JButton("9"));

Unit 1310 Example 3: Border Layout Test Container cp = getContentPane(); cp.setLayout(new BorderLayout()); cp.add(jb,"Center"); cp.add(new JButton("NORTH"), "North"); cp.add(new JButton("WEST"), "West"); cp.add(new JButton("EAST"), "East"); cp.add(new JButton("SOUTH"), "South"); setSize(300,300); setTitle("Grid Layout Test"); setVisible(true); } public static void main(String [] args){ new TestBorderLayout(); }

Unit 1311 Exercises 1.Move the call to the setVisible() method from the main() method to the TetFlowLayout constructor in Example 1. Then compile and run each of Examples 2, 3 and 4. You will notice some changes when displaying the frames. Explain. 2. Modify Example 2 to add two other types of borders to it. 3.Compare Example 2 and Example 3. In Example 2 we inherited a panel, added more components to it and then changed the panel’ÿ layout manager. In Example 3 we had to create an additional panel. Can Example 3 be written in similar manner to Example 2 without the additional panel? If it is possible, write the equivalent program otherwise explain why it is not possible. 4.Change the fill constraint variable on Line 13 from BOTH to each of the following: NONE, HORIZONTAL and VERTICAL. Run the program in each case and study the effect. 5.Change the value of the gridy constraint variable on Lines 29 to a smaller value. Run the program and observe the result. Do the same for the value on Line 32. Also change these values to bigger values and observe the results.