Java programming, Java Swing Programming, SWING GUI Design, desktop application, Getting Started with Swing application development in java, Introduction to GUI based programming in java, Java to standard edition, J2SE, Core Java, Swing package in java
2. ADVANCE JAVA
Author Profile
Ankit Desai
Ph.D. Scholar, IET, Ahmedabad University
Education: M. Tech. (C.E.), B. E. (I. T.)
Experience: 8 years (Academic and Research)
Research Interest: IoT, Big Data Analytics, Machine
Learning, Data Mining, Algorithms.
Classified e-Material 2
3. Classified e-Material 3
Swing Features
PasswordStore shows some of the rich functionality
of a particular Swing application. This lesson
discusses the general features available to
applications using the Java SE platform and, in
particular, the Swing toolkit.
4. Classified e-Material 4
Index
Swing Features
1. A Visual Guide to Swing Components (Java Look and
Feel)
2. A Visual Guide to Swing Components (Windows Look
and Feel)
3. Pluggable Look and Feel
4. Data Transfer
5. Internationalization and Localization
6. Accessibility
7. Integrating with the Desktop System Tray Icon
Support
5. Classified e-Material 5
Swing Features
1. A Visual Guide to Swing Components (Java
Look and Feel)
Swing is primarily known for its rich set of GUI
components. This section provides a visual menu of
Swing's components, grouped by type, using the
Java look and feel.
6. Classified e-Material 6
Swing Features
2. A Visual Guide to Swing Components
(Windows Look and Feel)
This section shows the same components, using the
Windows look and feel.
7. Classified e-Material 7
A Visual Guide to Swing Components
(Java Look and Feel v/s Windows Look
and Feel)
8. Classified e-Material 8
Basic Controls
Simple components that are used primarily to get
input from the user;
they may also show simple state.
12. Classified e-Material 12
Interactive Displays of Highly Formatted Information
These components display highly formatted
information that
(if you choose) can be modified by the user.
27. Classified e-Material 27
Swing Features
3. Pluggable Look and Feel
The pluggable look and feel architecture allows a
program to have control over its appearance. This
section describes what options are available to the
programmer.
28. Classified e-Material 28
Pluggable Look and Feel
The Swing toolkit allows you to decide how to
configure the particular 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.
34. Classified e-Material 34
Swing Features
4. Data Transfer
Most programs will want to use drag and drop or cut,
copy and paste. This section talks a bit about data
transfer and what is implemented for you.
35. Classified e-Material 35
Drag and Drop
Drag-and-drop support can be easily enabled for
many of Swing's components (sometimes with a
single line of code). For example, it's trivial to
enable drag and drop and copy and paste support
for JTable, Swing's table component. All you need
to provide is the data representing the selection
and how to get your data from the clipboard —
that's it!
36. Classified e-Material 36
Cut, Copy, and Paste
Most of the text-based components, such as editor
pane and text field, support cut/copy and paste out
of the box. Of course, menu items need to be
created and "wired up" to the appropriate actions.
Other components, such as list and tree, can
support cut, copy, and paste with some minimal
work.
37. Classified e-Material 37
Swing Features
5. Internationalization and Localization
Internationalizing an application makes it easy to
tailor it to the customs and languages of end users
around the world. This section describes the
difference between internationalization and
localization.
38. Classified e-Material 38
Internationalization vs Localization
Internationalization is the process of designing an
application so that the user can run it using his or
her cultural preferences without modifying or
recompiling the code.
Localization is the process of translating the text to
a particular language and adding any locale-specific
components.
40. Classified e-Material 40
Swing Features
6. Accessibility
Making your program accessible means that it can be
used, without modification, by anyone with
permanent or temporary disabilities who may require
special devices. And, in many countries, making
programs accessible is the law.
41. Classified e-Material 41
Accessibility
The PasswordStore demo
follows the rules set out
for accessibility. In the
following figure, you can
see an example of tool
tip text.
PasswordStore With a Tooltip
42. Classified e-Material 42
Swing Features
7. Integrating with the Desktop
An application that is well integrated with the
desktop will, where appropriate, allow the user to
launch the default mail application or internet
browser, pre-populating text fields as needed. It will
also allow the user to launch another application to
open, edit or print a file associated with that
application.
43. Classified e-Material 43
Types
Three types of integration are supported:
Default browser with a specific Uniform Resource
Identifier (URI).
Default email client.
Applications to open, edit, or print files associated
with those applications.
44. Classified e-Material 44
Example
Click on the link that is
displayed in the text
pane — it opens the
specified URI in the
default browser.
Click on the URI and it opens in the Default
Browser
45. Classified e-Material 45
Swing Features
8. System Tray Icon Support
Some platforms, such as Microsoft Windows, feature
a system tray on the desktop. As of version 6 of the
Java SE, your application can now add a tray icon to
the system tray.
46. Classified e-Material 46
Snap Shot
The desktop of some platforms, such as Microsoft
Windows, includes a system tray, as shown in the
following screenshot:
47. Classified e-Material 47
Questions
Questions and Exercises: Graphical User Interfaces
1. Does Swing support multiple look and feels?
2. True or False: The Java look and feel is the only
look and feel that works across all platforms.
3. True or False: Swing's Undo Framework supports
an unlimited number of actions to undo (and redo).
4. Can Swing's list component (JList) only display
text?
5. Which Swing component provides undo support
out of the box?
6. Can Java applications interact with the native
desktop? components.
7. Can I deploy my Swing application on the web?
48. Classified e-Material 48
Answers to Questions and Exercises: Graphical User Interfaces
1. Does Swing support multiple look and feels? Yes. Sun
provides implementations for the GTK+ look and feel,
Windows look and feel, CDE/Motif look and feel, Synth (a
customizable look and feel), and two variants of the Java
look and feel.
2. True or False: The Java look and feel is the only look
and feel that works across all platforms.
True. The Java look and feel (also called Metal) comes in
two themes. Previous to the 5.0 release, the theme was
called Steel. The theme for 5.0 and beyond, is called
Ocean.
49. Classified e-Material 49
3. True or False: Swing's Undo Framework supports an
unlimited number of actions to undo (and redo).
True. Undo support is built-in to Swing's text component
and can be added to other components.
4. Can Swing's list component (JList) only display text?
No, as the demo illustrated you can display anything you
want in a JList, including rich graphics.
5. Which Swing component provides undo support out of
the box?
Swing's text components.
50. Classified e-Material 50
6. Can Java applications interact with the native
desktop? components.
Certainly, the Desktop API allows you to open up the
browser and various other services and the TrayIcon API
allows you to put a Swing component into the desktop
tray.
7. Can I deploy my Swing application on the web?
Certainly. You can use either Java Web Start or Java
Plugin.