Graphical User Interfaces
Graphical User Interfaces
We can create a graphical user interface (GUI) in the Java programming language through the Java Swing
toolkit.
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.
Java 2D API
The Java 2D API allows you to add images, figures, animations, drop shadows and compositing to your
applications.
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.
Swing’s undo framework allows developers to provide support for undo and redo functionalities.
SWING FEATURES
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
JColorChooser
JFileChooser
JTable
JTextArea
JTree
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
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.
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.
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.