Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Graphical User Interfaces1

GRAPHICAL USER INTERFACES

We can create a graphical user interface (GUI) in the Java programming language through the Java Swing
toolkit.

A BRIEF INTRODUCTION TO THE SWING PACKAGE

What is Swing?
The Swing toolkit includes a rich set of components for building graphical user interfaces and adding
interactivity to Java applications. It includes all the components you would expect from a modern toolkit,
from table controls to list controls and from buttons to labels.

Swing is a part of the Java Foundation Classes (JFC) which includes features important to a GUI
program.

Swing and JFC features:


O Swing GUI Components
O Java 2D API
O Pluggable Look-and-Feel Support
O Data Transfer
O Internationalization
O Accessibility API
O Undo Framework API
O Flexible Deployment Support

Swing GUI Components


The Swing toolkit includes a rich array of components from basic (buttons, check boxes) to rich and
complex components (tables and text).

Java 2D API
The Java 2D API allows you to add images, figures, animations, drop shadows and compositing to your
applications.

Pluggable Look-and-Feel Support


Swing components and JFC classes provides a look and feel that matches the platform it is running on.

Data Transfer
Swing supports cut, copy, paste, drag and drop, which are essential to any application.

Internationalization
This features allows developers to build applications that can interact with users worldwide in their own
languages and cultural conventions. Applications can be created to accept input in languages that use
thousands of different characters, such as Japanese, Chinese, or Korean.

Accessibility API
The accessibility API enables assistive technologies to programmatically manipulate the elements that
make up the graphical user interface. Assistive technologies are special software used by people with
disabilities such as a screen reader that renders a Braille display, a screen magnifier, on-screen keyboards,
and voice control systems.

Undo Framework API


Graphical User Interfaces2

Swing’s undo framework allows developers to provide support for undo and redo functionalities.

Flexible Deployment Support


Swing provides different types of launching your application. If you want your program to launch from a
browser, you can do this with the Java Web Start. You can also run your program as a standard desktop
application. Or if you want your program to run within a browser window, you can create it as an applet
and run it using Java Plug-in, which supports a variety of browsers.

SWING FEATURES

A Visual Guide to Swing Components


The following shows the list of components in the Java Swing toolkit.

Basic Controls
These are simple components that are used primarily to get input from the user and may also show simple
state.

JButton

JCheckBox

JComboBox

JList
Graphical User Interfaces3

JMenu

JRadioButton

JSlider

JSpinner
JTextField
JPasswordField

Interactive Displays Of Highly Formatted Information


These components display highly formatted information that (if you choose) can be modified by the user.
Graphical User Interfaces4

JColorChooser

JEditorPane and JTextPane


Graphical User Interfaces5

JFileChooser

JTable

JTextArea

JTree

Uneditable Information Displays


These components exists solely to give the user information.

JLabel

JProgressBar
Graphical User Interfaces6

JSeparator
JToolTip

Top-Level Containers
At least one of these components must be present in any Swing application.

JApplet

JDialog

JFrame

General-Purpose Containers
These containers are used in most Swing applications.

JPanel
Graphical User Interfaces7

JscrollPane

JSplitPane

JTabbedPane

JToolBar

Special-Purpose Containers
These containers play specific roles in the UI.
Graphical User Interfaces8

JInternalFrame

JLayeredPane

Root pane

Pluggable Look and Feel


The Swing toolkit allows you to decide how to configure the look and feel of your application. If you
don’t specify a look and feel, the Swing UI manager figures out which one to use.

Options for setting up a look and feel:


O Default Look and Feel = Leave it up to the Swing UI manager. If a particular look and feel is not
specified by the program, Swing UI manager checks whether the user has specified a preference, else the
default look and feel is used. Java look and feel works on all platforms.

O Native Platform Look and Feel = If the application is running on Microsoft Windows XP machine,
the Windows look and feel is used. On Mac OS, the Aqua look and feel is used. On Solaris and Linux, the
GTK+ or the CDE/Motif look and feel is used.

O Personalized Look and Feel = You can specify any look and feel available from Swing or other
available from the Internet.
Graphical User Interfaces9

O Synth Look and Feel = You can create your own look and feel using the Synth package.

O External Look and Feel = You can use an externally provided look and feel.

Data Transfer
The Swing toolkit supports the ability to transfer data between components within the same Java
applications, between different Java applications, and between Java and native applications.

Forms:
O Drag and Drop = This support can be easily enabled for many of Swing’s components.
O Cut, Copy, and Paste = Most of the text-based components, such as editor pane and text field, supports
cut/copy and paste. Other components, such as list and tree, also supports cut/copy and paste.

Internationalization and Localization


INTERNATIONALIZATION
= process of designing an application that can run on a user’s cultural preferences without modifying or
recompiling the code.

CULTURAL PREFERENCES
= known as locale includes language, currency formatting, time and date formatting, and numeric
formatting.

LOCALIZATION
= the process of translating the text to a particular language and adding any locale-specific components.

Swing’s layout manager understands how locale affects a UI. For example, if an application is set to a
new language preference, components such as menus, labels and buttons, in the application adjusts or
scales according to the new character set. In a locale where text flows from right to left, such as in
Hebrew and Arabic, the layout manager will arrange components in the same direction, if specified.

Accessibility
Assistive technologies exists to enable people with disabilities to use the computer. Assistive technologies
includes voice interfaces, magnifiers, screen readers, closed captioning, keyboard enhancements, and
others.

For example, you can assign simple rules achieve accessibility such as tool tips, shortcut keys, and textual
descriptions for images.

Integrating With the Desktop


The Desktop API enables Java applications to integrate with the desktop.

3 types of integration supported by the Desktop API:


 Ability to launch the host system’s default browser with a specific uniform resource identifier (URI).
 Ability to launch the host system’s default email lient.
 Ability to launch applications to open, edit, or print files associated with those applications.
Graphical User Interfaces10

System Tray Icon Support


Desktop of some platforms includes a system tray as show below.

A system tray is shared by all applications.

TRAY ICON
= a mini-icon that an application inserts in a system tray that can be used to notify the user of a change in
an application’s status, or a need to take a particular action.

Clicking the tray icon can bring up the application window. A popup menu and a tooltip can also be
attached to the tray icon.

You might also like