Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
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.
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
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
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.
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
1 L48 Advanced GUI Component (3). 2 OBJECTIVES  To use additional layout managers.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
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.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
CS3 - AWT/Swing1 The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness –The Abstract.
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
1 Chapter 22 Containers, Layout Managers, and Borders.
Java Programming Chapter 10 Graphical User Interfaces.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
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.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Graphical User Interface Components Chapter What You Will Learn Text Areas Text Areas Sliders Sliders Menus Menus –With frames –Pop up menus Look.
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.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
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.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
Layout Managers Arranges and lays out the GUI components on a container.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
Layout Manager Summary
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
CSCI Swing1 The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness –The Abstract.
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.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
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.
University of Limerick1 Software Architecture Java Layout Managers.
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.
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
CPSC 233 Tutorial Xin Apr 6, Reading files An example available on my website pages.cpsc.ucalgary.ca/~liuxin.
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.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 3 Designing the Interface with Layout Managers.
Java Swing - Lecture 3 Layout Management
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
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.
A Quick Java Swing Tutorial
Provision for GUIs in Java
University of Central Florida COP 3330 Object Oriented Programming
Advanced GUI Programming
University of Central Florida COP 3330 Object Oriented Programming
Provision for GUIs in Java
Containers and Components
תכנות מכוון עצמים בשפת JAVA
Tim McKenna Layout Mangers in Java Tim McKenna
Panels & Layout Managers
Chapter 33 Containers, Layout Managers, and Borders
GUI Layouts By: Leonard & Saif.
Presentation transcript:

Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001

© Benko 2001 Containers

© Benko 2001 Swing Top-Level Containers heavyweight: JFrame, JDialog, JWindow, JApplet – extend AWT containers – platform-depended code – every component takes on the look-and-feel of the platform on which the program currently executes lightweight: JInternalFrame – completely written in Java – provides uniform functionality across platforms as well as the uniform cross-platform look-and-feel

javax.swing

© Benko 2001 Understanding Swing Top-Level Containers We NEVER add() any components directly to the top-level container Instead we add() to the container’s content pane: – content pane is a repository for the components added to the container – obtained by getContentPane() method – content pane is an object of the JRootPane

© Benko 2001 What is JRootPane? It provides the architectural structure of the Swing container hierarchy. JRootPane object is not usually created by user, but instead it is given automatically whenever one creates a container Adding children, setting layout managers, adding/removing components to the JRootPane is NOT ALLOWED All those actions have to be done to the content pane!!!

© Benko 2001 JRootPane Information Root pane is made up of: – contentPane – glassPane (used for intercepting mouse events and drawing) – JMenuBar (optional) The content pane and the menu bar are managed by JLayeredPane

© Benko 2001 Why is JLayeredPane needed? It provides depth to the JFC/Swing container Allows components to overlap each other when needed

© Benko 2001 Explanation of Layers Default - standard layer where most components go Palette - used for floating toolbars and palettes Modal - used for modal dialogs Popup - used for popup windows, combo boxes, tooltips, help text Drag - for displaying components while they are being dragged across the screen

© Benko 2001 Frame Hierarchy - Summary

© Benko 2001 Additional Swing Containers JPanel (default container) JSplitPane Box container JTabbedPane JDesktopPane JScrollPane JViewport JTextPane JEditorPane

Layout Managers

© Benko 2001 Java2™ Layout Managers Arrange GUI components on a container for presentation purposes Abstract the idea of positioning widgets on the screen Enables the programmer to concentrate on the functionality of their program and lets the layout managers process most of the layout details

© Benko 2001 Java2™ Layout Managers FlowLayout BorderLayout CardLayout BoxLayout GridLayout GridBagLayout

© Benko 2001 FlowLayout Default for java.awt.Applet, java.awt.Panel and javax.swing.JPanel Places components sequentially (left to right) in the order they were added

© Benko 2001 BorderLayout Default for content panes of JFrames and JApplets Places components into five areas: – “Center” – “North” – “South” – “East” – “West”

© Benko 2001 CardLayout A layout manager that stacks components like a deck of cards Only the component at the “top” of the deck is visible Methods to use: first(), next(), previous(), last()

© Benko 2001 BoxLayout Allows GUI components to be arranged in a container: – left-to-right (horizontally) – top-to-bottom (vertically) Class Box defines a container with BoxLayout as its default layout manager

© Benko 2001 GridLayout Arranges the components into rows and columns Order of addition to the container matters

© Benko 2001 GridBagLayout Similar to GridLayout Difference: each component size can vary and components can be added in any order desired

© Benko 2001 GridBagLayout To use GridBagLayout you must construct GridBagConstraints object GridBagConstraints instance variables: – gridx (column) – gridy (row) – gridwidth (column span) – gridheight (row span) – weightx (horizontal extra space allocation) – weighty (vertical extra space allocation)

© Benko 2001 Others… OverlayLayout (used by JButton) ScrollPaneLayout (used by JScrollPane) ViewportLayout (used by JViewport) AbsoluteLayout (non-standard - Forte specific) You can write your own layout manager: – All you have to do is implement correctly the LayoutManager interface

© Benko 2001 “Look-and-feel”

© Benko 2001 Swing pluggable “look-and-feel” Swing provides flexibility to customize the “look-and-feel” automatically: – MS Windows style – Motif style (UNIX) – Metal (Java default) – or any other custom l&f UIManager.setLookAndFeel()