jdk/src/share/classes/javax/swing/package.html
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
<HTML>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
<HEAD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
<!--
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
        <META NAME="Author" Content="Eric Armstrong">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
        <TITLE>swing package</TITLE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
</HEAD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
<BODY bgcolor="white">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
<P>Provides a set of &quot;lightweight&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
(all-Java language) components that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
to the maximum degree possible, work the same on all platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
For a programmer's guide to using these components, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
<a href="http://java.sun.com/docs/books/tutorial/uiswing/index.html" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
target="_top">Creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
a GUI with JFC/Swing</a>, a trail in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
For other resources, see 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
<a href="#related">Related Documentation</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
<H2><a name="threading">Swing's Threading Policy</a></h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
In general Swing is not thread safe. All Swing components and related
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
classes, unless otherwise documented, must be accessed on the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
dispatching thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
Typical Swing applications do processing in response to an event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
generated from a user gesture. For example, clicking on a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
JButton} notifies all {@code ActionListeners} added to the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
JButton}. As all events generated from a user gesture are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
dispatched on the event dispatching thread, most developers are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
impacted by the restriction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
Where the impact lies, however, is in constructing and showing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
Swing application. Calls to an application's {@code main} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
or methods in {@code Applet}, are not invoked on the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
dispatching thread. As such, care must be taken to transfer control
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
to the event dispatching thread when constructing and showing an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
application or applet. The preferred way to transfer control and begin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
working with Swing is to use {@code invokeLater}. The {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
invokeLater} method schedules a {@code Runnable} to be processed on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
the event dispatching thread. The following two examples work equally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
well for transferring control and starting up a Swing application:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public class MyApp implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        // Invoked on the event dispatching thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        // Construct and show GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        SwingUtilities.invokeLater(new MyApp(args));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
Or:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
public class MyApp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    MyApp(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // Invoked on the event dispatching thread. Do any initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        // Show the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static void main(final String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // Schedule a job for the event-dispatching thread:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // creating and showing this application's GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        SwingUtilities.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                new MyApp(args).show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
This restriction also applies to models attached to Swing components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
For example, if a {@code TableModel} is attached to a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
JTable}, the {@code TableModel} should only be modified on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
event dispatching thread. If you modify the model on a separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
thread you run the risk of exceptions and possible display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
corruption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
As all events are delivered on the event dispatching thread, care must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
be taken in event processing. In particular, a long running task, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
as network io or computational intensive processing, executed on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
event dispatching thread blocks the event dispatching thread from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
dispatching any other events. While the event dispatching thread is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
blocked the application is completely unresponsive to user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
input. Refer to {@link javax.swing.SwingWorker} for the preferred way to do such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
processing when working with Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
More information on this topic can be found in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
<a href="http://java.sun.com/docs/books/tutorial/uiswing/">Swing tutorial</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
in particular the section on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
<a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html">How to Use Threads</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
<H2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
<a name="related">Related Documentation</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
</H2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
<P>For overviews, tutorials, examples, guides, and other documentation, please see:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
<UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
   <LI><A HREF="http://java.sun.com/products/jfc/tsc/" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
   target="_top">The Swing Connection</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
   <LI><A HREF="http://java.sun.com/docs/books/tutorial/" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
   target="_top">The Java Tutorial</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
   <LI><A HREF="http://developer.java.sun.com/developer/onlineTraining/" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
   target="_top">Online Training</A> at the Java Developer Connection<font size=-2><sup>SM</sup></font>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
   <LI><A HREF="http://java.sun.com/products/jfc/" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
   target="_top">Java Foundation Classes (JFC)</A> home page
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
</UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
@serial exclude
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
</BODY>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
</HTML>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147