Spec-Zone .ru
спецификации, руководства, описания, API
|
Both GTK and Windows look and feels were enhanced and improved by taking advantage of native rendering engines. All Swing components appear in accordance with the underlying platform's look and feel, provide appropriate feedback and have the correct size.
An abstract class SwingWorker
class enables a long-running task to be
executed on a background thread. A subclass of
SwingWorker
must implement the doInBackground()
SwingWorker
class
supports intermediate results. The background task can invoke the
publish
process
SwingWorker
class
supports property change listeners. Any change of a property
triggers an event, which invokes event-handling methods on the
event dispatch thread.
The use of the SwingWorker is recommended to accomplish
time-consuming tasks. For details, see the
Several new methods of the
The new API includes the following methods:
To provide sorting and filtering capabilities, several new
classes were added to the JDK. The basis for sorting and filtering
is provided by the abstract RowSorter
class that deals with grid-based models. The
RowSorter
class for JTables. The
TableRowSorter
class enables you to specify different
Comparator
s and also provides a filtering option.
For details, see the
The new API is intended for developers who write layout managers and includes the following two features: an ability to get the baseline for components and an ability to get the preferred spacing between components.
Professional layouts typically align components along their
baseline. Previously, Swing provided no means to get the baseline
of components. As a solution to this problem, the
Each look and feel provides different guidelines regarding how
far components should be placed from each other. In order to create
a cross platform look and feel there should be an API for getting
this information. As a solution, the getLayoutStyle()
method
of the look and feel.
Prior to release 6, the content of a tabbed pane's tab was
limited to a string or an icon (or both). The new API allows you to
add custom components to tabs. The most common use of this feature
is to add close buttons that remove tabs from tabbed panes. The
following new methods were added to the
For details, see the
Each window has an off-screen image that is synchronised with the corresponding on-screen image. As a window is exposed, its off-screen image is directly copied on the toolkit thread to the screen. Another benefit applies to applications that block the event dispatch thread. If a user hides and then exposes an application window, the application still paints while the EDT is being blocked.
In addition, the JApplet
, JWindow
,
JFrame
, and JDialog
) and supports new
painting architecture based on a component's location in the
window. The following new methods were added to the
RepaintManager
class:
All Swing top-level components override the repaint
method, which calls the appropriate addDirtyRegion
method.
The setDoubleBuffered
method,
which defines whether this component should use a buffer for
painting or not.
The javax.swing
package. This layout was developed for the
GUI builder provided with the NetBeans IDE. The
GroupLayout
is primarily intended for use by GUI
builders but may be hand-coded as well.
For details, see the
Two major enhancements were introduced to the Drag and Drop feature in release 6.
First, the Drag and Drop operation can be configured not to use
a selection for showing a drop location (refer to the Bug Database,
bug ID JTree
, JTable
, JList
, and
JTextComponent
. The DropMode
property is
used to determine the mode by which a component tracks and
indicates a drop location. To set this property for a component,
the setDropMode(DropMode)
method was added to the
component's class for each component mentioned above. Listed below
are available drop modes and the components that support them:
ON
- JList
, JTree
,
JTable
INSERT
- JList
, JTree
,
JTable
, JTextComponent
ON_OR_INSERT
- JList
,
JTree
, JTable
ON_OR_INSERT_ROWS, ON_OR_INSERT_COLS
-
JTable
USE_SELECTION
- JList
,
JTree
, JTable
,
JTextComponent
For backward compatibility the default value of this property is
set to USE_SELECTION
. To take advantage of the
improved Drag and Drop feature, use one of the other drop modes
mentioned above.
The second enhancement involves the TransferHandler
class with regard to handling drop operations. Previously, the
TransferHandler
class was unable to accomplish common
drop-related tasks since import handling methods lacked necessary
information. The new
New overloaded versions of the TransferHandler
class. These methods take an instance
of the TransferSupport
class and thus allow developers
to accept or reject transfers based on the details of the transfer.
Developers can also customize drop behavior based on a
Transferable
, a drop location, or a drop action
associated with a transfer retrieved from the
TransferSupport
instance. For example, the new
canImport
method can be implemented to detect an
attempt to move data from a child to its parent and reject such a
transfer. Unlike previous versions, the canImport
method is called continuously by a component's
TransferHandler
, while a drag and drop operation takes
place over the component. This feature provides the mechanism by
which the acceptability of a transfer can be changed many times
during the operation. For backward compatibility, the old version
of the canImport
method is called by the new version
by default.
Another improvement includes addition of TransferHandler support
to top-level components. This support is provided by means of the
setTransferHandler
and getTransferHandler
methods added to the class of each top-level component
(JApplet
, JWindow
, JFrame
,
and JDialog
).
Previously users had to make a selection first and then click
the selected item again to initiate a drag operation. Now a drag
operation is initiated with a single mouse click (refer to the Bug
Database, bug ID
For details, see the
Nimbus, a cross platform look and feel introduced in the Java SE 6 update 10 release, is drawn with 2D vector graphics and can be rendered at any resolution. See Nimbus Look and Feel for more information.
The ButtonGroup
class is used to create a
multiple-exclusion scope for a set of buttons. Initially all
buttons in a group are unselected. Previously there was no way to
return to the unselected state after selecting a button. Now the
The following constants were added to the
SELECTED_KEY
JRadioButton
and JCheckBox
instances.DISPLAYED_MNEMONIC_INDEX_KEY
LARGE_ICON_KEY
hideActionText
property determines whether a
button displays the text from the Action
. To set and
get this property, the following new methods were added to the
AbstractButton
class: JDialog d = new JDialog((Dialog)null);
Swing only allowed you to pass null
to the
constructor JDialog(Frame):
JDialog d = new JDialog((Frame)null);
In the latter case an invisible shared-owner frame was a parent for all parentless JDialogs.
With the new d.getParent()
returns null
for these dialogs. To make use of new
modality API, JDialogs also need to be truly parentless (refer to
the Bug Database, bug ID
New constructors with a Window
parameter as an
owner were added to the JDialog
class and a new method
was added to the JOptionPane
class. To create a
parentless JDialog, you can now pass null
to either of
constructors JDialog(Dialog)
or
JDialog(Window)
. To create a parentless JOptionPane,
use the
As a summary, have a look at the three constuctors below:
JDialog d = new JDialog((Dialog)null)
;
JDialog d = new JDialog((Window)null)
;
JDialog d = new JDialog((Frame)null)
;
Note the difference: although all three constructors take
null
, only the first two dialogs are truly parentless
and the operation d.getParent()
returns
null
for them. For the third dialog
d.getParent()
returns the shared-owner frame.