Graphical User Interface (GUI)

Similar documents
Graphical User Interface (GUI)

Containers and Components

Introduction to the JAVA UI classes Advanced HCI IAT351

Graphic User Interfaces. - GUI concepts - Swing - AWT

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

CS 251 Intermediate Programming GUIs: Components and Layout

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

encompass a group of features for building Graphical User Interfaces (GUI).

JFrame In Swing, a JFrame is similar to a window in your operating system

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

No SVN checkout today. Object-Oriented Design

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Laying Out Components. What is Widget Layout?

Layout. Dynamic layout, Swing and general layout strategies

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

FirstSwingFrame.java Page 1 of 1

Graphical User Interfaces. Comp 152

Lecture 9. Lecture

Using NetBeans IDE for Desktop Development. Geertjan Wielenga

Graphical User Interface (GUI)

Java Swing Introduction

Dr. Hikmat A. M. AbdelJaber

Part I: Learn Common Graphics Components

Basicsof. JavaGUI and SWING

Final Examination Semester 2 / Year 2010

CompSci 230 S Programming Techniques. Basic GUI Components

BASICS OF GRAPHICAL APPS

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Layout. Dynamic layout Layout design pattern Layout strategies

Final Examination Semester 2 / Year 2011

Layout. Dynamic layout Layout design pattern Layout strategies. 2.6 Layout 2

Section Basic graphics

Java: Graphical User Interfaces (GUI)

Graphical User Interfaces

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

2IS45 Programming

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

CSCI 201L Midterm Written SOLUTION Fall % of course grade

More Swing. Chapter 14. Chapter 14 1

Building Graphical User Interfaces. Overview

First Name: AITI 2004: Exam 2 July 19, 2004

Building Java Programs Bonus Slides

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Chapter 12 Advanced GUIs and Graphics

WIMP Elements. GUI goo. What is WIMP?

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Top-Level Containers

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation

Netscape Composer: Working with Tables

Inserting a table plus all related tips on the table

Graphical User Interface (GUI)

Building Graphical User Interfaces. GUI Principles

Using Several Components

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Unit 6: Graphical User Interface

Summary Chapter 25 GUI Components: Part 2

Final Examination Semester 2 / Year 2012

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

The Java Programming Language Basics. Identifiers, Keywords, and Types. Expressions and Flow Control. Object-Oriented Programming. Objects and Classes

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

1. Swing Note: Most of the stuff stolen from or from the jdk documentation. Most programs are modified or written by me. This section explains the

Chapter 14. More Swing

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Dreamweaver Tutorials Working with Tables

I.1 Introduction Matisse GUI designer I.2 GroupLayout Basics Sequential and Parallel Arrangements sequential horizontal orientation

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

CS 2113 Software Engineering

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Human-Computer Interaction IS4300

1005ICT Object Oriented Programming Lecture Notes

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

SWING - GROUPLAYOUT CLASS

10/23/2008. CSG 170 Round 6. Prof. Timothy Bickmore. Quiz. Open book / Open notes 15 minutes

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

PIC 20A GUI with swing

YouTube Break.

Event Driven Programming

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Graphical User Interfaces 2

Lecture 18 Java Graphics and GUIs

Java Programming Lecture 6

First Name: AITI 2004: Exam 2 July 19, 2004

Transcription:

Graphical User Interface (GUI) Layout Managment 1

Hello World Often have a run method to create and show a GUI Invoked by main calling invokelater private void run() { } JFrame frame = new JFrame("HelloWorldSwing"); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.add(new JLabel("Hello World")); frame.pack(); frame.setvisible(true); 2

Problem GUI has lots of parts Making a GUI easy to use requires logical layout But screens should be dynamic and resizable! How do you manage layout of components? 3

Collect multiple Components in Container Most often, JPanel (or Jframe.contentPane()) Use a panel for a rectangular sub-section of the GUI Add a component to a container with the add method add(component) or add(component,layout_hints) Each container has a Layout Manager Determines where to put the components in the container Invoked when Container is first built Invoked when Container is re-sized May request components to resize Default Layout Manager for JPanel is FlowLayout 4

Managing the Layout Manager Layout manager may be an argument to a Container Constructor e.g public JPanel (LayoutManager layout) Create a new buffered JPanel with the specified layout manager Contain class has a setlayout (and getlayout) method public void setlayout (LayoutManager mgr) Sets the layout manager for this container. Inherited by all classes which extend Container 5

Flow Layout Manager Like writing or reading English Components appear in the order they are added Left to right until you get to the right margin Components assume their natural (preferred) sizes Default gap between components is 5 pixels How wide is the enclosing panel? Then go to a new line 6

Box Layout Single row or column of components When creating layout, specify BoxLayout.X_AXIS or BoxLayout.Y_AXIS When creating, the layout manager, you have to specify container as an argument (different from other layouts) Components appear in the order they are added 7

Border Layout Specify position when adding components When resizing Center expands both x and y North/South expands x, West/East expands y By default, there is a 5 pixel gap between components Unused positions take no space Only one component per position Layout hint: panel.add(button,borderlayout.east); It s surprising how much this handles! 8

Grid Layout Useful when components are in a grid Specify rows/cols as argument to constructor 0 indicates as many as needed All components same size Resized to fit container Fills in left to right then top to bottom 9

GridBag Layout Extends the Grid concept by allowing components to span multiple rows/cols Each row and column can have different size Flexible and adaptable Requires the most code Specify constraints when adding components Constraints define grid coordinates of upper left corner and things like padding, grid width, grid height, etc. See the GridBagContraints class for more details 10

Card Layout Use when you want multiple versions of the display Each version is on it s own card a new Jpanel Each card can have its own layout manager You specify which card is currently displayed Similar to a tabbed windows (JTabbedPane) 11

Component Resizing It is possible to set a minimum, preferred, and maximum size on each component yellowlabel.setpreferredsize(new Dimension(200, 180)); yellowlabel.setminimumsize(new Dimension(100,20)); yellowlabel.setmaximumsize(new Dimension(600,800)); It would be nice if the layout managers all respected these constraints (they don t but some, like GridBagLayout, do) 12

Java Layout Tutorial See https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html We haven t covered them all SpringLayout, GroupLayout 13

Adding Borders Every component can have its own borders Borders are created by the BorderFactory class see https://docs.oracle.com/javase/tutorial/uiswing/components/bo rder.html for some examples 14

Popup Dialogs There is a JDialog class for creating custom dialogs, but Simple popup messages are just JOptionPane.showMessageDialog(this,"Amount not recognized."); 15