28-11-2012, 02:25 PM
The Java Swing tutorial
The_Java_Swing_tutorial.pdf (Size: 1.36 MB / Downloads: 566)
Introduction to the Java Swing Toolkit
About this tutorial
This is an introductory Swing tutorial. The purpose of this tutorial is to get you started with
the Java Swing toolkit. The tutorial has been created and tested on Linux.
SWT library
There is also another GUI library for the Java programming language. It is called SWT. The
Standard widget toolkit. The SWT library was initially developed by the IBM corporation.
Now it is an open source project, supported by IBM. The SWT is an example of a
heavyweight toolkit. It lets the underlying OS to create GUI. SWT uses the java native
interface to do the job. The main advantages of the SWT are speed and native look and feel.
The SWT is on the other hand more error prone. It is less powerful then Swing. It is also
quite Windows centric library.
Menus and toolbars in Java Swing
Creating a menubar
A menubar is one of the most visible parts of the GUI application. It is a group of commands
located in various menus. While in console applications you had to remember all those
arcane commands, here we have most of the commands grouped into logical parts. There
are accepted standards that further reduce the amount of time spending to learn a new
application.
In Java Swing, to implement a menubar, we use three objects. A JMenuBar, a JMenu and
a JMenuItem.
Java Swing dialogs
Dialog windows or dialogs are an indispensable part of most modern GUI applications. A
dialog is defined as a conversation between two or more persons. In a computer application
a dialog is a window which is used to "talk" to the application. A dialog is used to input data,
modify data, change the application settings etc. Dialogs are important means of
communication between a user and a computer program.
In Java Swing toolkit, we can create two kinds of dialogs. Custom dialogs and standard
dialogs. Custom dialogs are dialogs, created by the programmer. They are based on
the JDialog class. Standard dialogs preedefined dialogs available in the Swing toolkit. For
example JColorChooser or JFileChooser. These are dialogs for common programming
tasks like showing text, receiving input , loading and saving files etc. They save
programmer's time and enhance using some standard behaviour.
There are two basic types of dialogs. Modal and modeless. Modal dialogs block input to
other top level windows.Modeless dialogs allow input to other windows. What type of dialog
to use, depends on the circumstances. An open file dialog is a good example of a modal
dialog. While choosing a file to open, no other operation should be permitted. A typical
modeless dialog is a find text dialog. (Like in Eclipse IDE.) It is handy to have the ability to
move the cursor in the text control and define, where to start the finding of the particular
text.