We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Modified over 6 years ago
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
© 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
© 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()
Introduction to Java 2 Programming
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.
© 2021 SlidePlayer.com Inc. All rights reserved.