SWING 101.0. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:

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

Introduction to Java 2 Programming
Graphic User Interfaces Layout Managers Event Handling.
Java Foundation Classes (JFC/Swing) Carl Alphonce revised Spring 2007 (with contributions from Alan Hunt)
Introduction to JFC Swing Written by Adam Carmi. Agenda About JFC and Swing Pluggable Look and Feel Swing Components Borders Layout Management Events.
 What are the basic GUI components we’ve learned so far? › JFrame › JPanel › JButton › JLabel › JTextArea › JTextField › JCheckBox › JRadioButton › Paint.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Eric Stokes, Matt Behling. GridbagLayout CardLayout SpringLayout.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
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.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
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.
Creating GUIs in Java using Swing David Meredith Aalborg University.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
Written by Liron Blecher
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
Welcome to CIS 083 ! Events CIS 068.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
CHAPTER:06 JAVA IDE PROGRAMMING-I Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
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.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
GUI development in Java L. Grewe Two methodologies for things to appear on the screen 1. By painting / drawing e.g. drawing an Image e.g. drawing an.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Concurrent Programming and Threads Threads Blocking a User Interface.
SWING 101. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
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.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Programming with Java’s Swing API February 4, 2003 CMPS Advanced Programming Graphical User Interfaces.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane.
Software Design 5.1 From Using to Programming GUIs l Extend model of "keep it simple" in code to GUI  Bells and whistles ok, but easy to use and hide.
Swing / Session1 / 1 of 30 Module Introduction Distributed Computing in Java.
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.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Developing GUIs With the Eclipse Visual Editor, Swing/AWT Edition David Gallardo.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
Java Swing. Note - this presentation.. often needs to refer to source code which is too big to put on a slide So the source code is in a separate Word.
Module 13: Swing API Object Oriented Programming(Java)
A Quick Java Swing Tutorial
Provision for GUIs in Java
Provision for GUIs in Java
Introduction to Graphical Interface Programming in Java
תכנות מכוון עצמים בשפת JAVA
Creating Graphical User Interfaces
Steps to Creating a GUI Interface
Week 8 Swing NetBeans GUI Builder
Presentation transcript:

SWING 101.0

IF YOU GET LOST - IMPORTANT LINKS  Swing articles:  Swing Architecture:  Visual Editor for Eclipse:  Oracle Swing tutorial:  Stack Overflow:  Basic Swing tutorial:

SWING COMPONENTS HIERARCHY  Tutorial   Components   Layout 

PAINT AND LAYOUT  Swing components painting and layout order  First you set properties on components  Then swings lays outs components  Then paints them  Note: until the top level container has been set to visible and laid out you can not know the size and location of your component  paint, repaint, invalidate, validate  paint() – paints the component. Invoked internally by Swing – DO NOT USE  repaint() – instructs Swing to paint the given region when the “time is right” – Safe to use  validate() –checks if the container (and its children) have been changed and if so instructs Swing to perform a re-layout  invalidate() –marks a container as invalid but does not perform a re-layout

CONTAINERS  The main containers are: JPanel, JSplitPane, JScrollPane and JTabbedPane  Have properties that defines their looks and behavior (just like components)  Don’t have data models  Have events (mouse events, size changes events, etc.)  Adding components– add the component to the children list of the container and set the component parent to be the container  When you add a component you link it to the container – not create a copy of it in the container  getParent() – for containers and components  getChildren() – for containers only  Each component or container has a single parent

LAYOUT MANAGER  Only valid for containers  Automatically set the size and location of all the child components in the container  Different layout algorithms – some have properties (for example: gap between components)  Some require additional data for each child component – that data should be added in advanced when adding a component to a container  Settings size constrains (size, preferred, minimum, maximum) 

COMPLEX LAYOUT  A container an contains child containers (same as components)  When it resizes – all of its child containers will be resized as well and then re-layout their child component recursively  You can mix different layout algorithms (for example: a JPanel with Border Layout that contains 3 JPanels with Flow Layout each)

ACTIONS  Just like the interface Runnable – this is Swing’s way to pass “a parameter of a method to a component” – meaning, pass some code to execute when a common event occurs  Actions are not JComponents (not UI objects)  The same action instance can be passed to several UI components (menu item, JButton, etc.)  Actions have properties for the component that will use them:  Label  Icon  Tooltip

DIALOGS  JDialogs are Top-Level containers  Open a dialog that displayed some content (like JFrame)  To set custom content – add it to the dialog’s content pane  After calling setVisible(true) on a dialog – no events are dispatched to the rest of the UI components (except in the dialog itself)  You can customize the dialog’s buttons (change the number of buttons, the text on each button, etc.)  ml ml

GUI EDITORS  Great for all the things in the world… except when you need to change a component programmatically  Here are some recommendations:  NetBeans  JFormDesigner  Eclipse UI editor  Another issue – some editors might add dependencies on external Jars (which you’ll need to bundle with your complied code in order for it to execute)  Adding external jars to project

OTHER SWING STUFF  Menus  Renderers (and Editors)  How to set native look and feel  Selection events, change events(Optional)