Sun Microsystems, Inc.
www.sun.com
Submit comments about this document to: lwuit@sun.com
Developer’s Guide
Lightweight UI Toolkit
Part No. 07-2009
July 2009
Copyright © 2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.
Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. In
particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at
http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. and in other countries.
U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and
applicable provisions of the FAR and its supplements.
Use is subject to license terms.
This distribution may include materials developed by third parties.
Sun, Sun Microsystems, the Sun logo, Java, JAR, Java SE, Java ME, NetBeans, java, and the Java Coffee Cup logo are trademarks or registered
trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
The Adobe. logo is a registered trademark of Adobe Systems, Incorporated.
Sprint, the "Going Forward" logo, and other trademarks are trademarks of Sprint Nextel.
This product is covered and controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear,
missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or
reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied
persons and specially designated nationals lists is strictly prohibited.
Copyright © 2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits réservés.
Sun Microsystems, Inc. détient les droits de propriété intellectuels relatifs à la technologie incorporée dans le produit qui est décrit dans ce
document. En particulier, et ce sans limitation, ces droits de propriété intellectuelle peuvent inclure un ou plus des brevets américains listés à
l'adresse http://www.sun.com/patents et un ou les brevets supplémentaires ou les applications de brevet en attente aux Etats - Unis et
dans les autres pays.
L'utilisation est soumise aux termes de la Licence.
Cette distribution peut comprendre des composants développés par des tierces parties.
Sun, Sun Microsystems, le logo Sun, Java, JAR, Java SE, Java ME, NetBeans, java, et le logo Java Coffee Cup sont des marques de fabrique ou des
marques déposées de Sun Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
Le logo Adobe. est une marque déposée de Adobe Systems, Incorporated.
Sprint, the "Going Forward" logo, and other trademarks are trademarks of Sprint Nextel.
Ce produit est soumis à la législation américaine en matière de contrôle des exportations et peut être soumis à la règlementation en vigueur
dans d'autres pays dans le domaine des exportations et importations. Les utilisations, ou utilisateurs finaux, pour des armes nucléaires,des
missiles, des armes biologiques et chimiques ou du nucléaire maritime, directement ou indirectement, sont strictement interdites. Les
exportations ou réexportations vers les pays sous embargo américain, ou vers des entités figurant sur les listes d'exclusion d'exportation
américaines, y compris, mais de manière non exhaustive, la liste de personnes qui font objet d'un ordre de ne pas participer, d'une façon directe
ou indirecte, aux exportations des produits ou des services qui sont régis par la législation américaine en matière de contrôle des exportations et
la liste de ressortissants spécifiquement désignés, sont rigoureusement interdites.
iii
Contents
Preface ix
1. Introducing the Lightweight UI Toolkit Library 1–1
1.1 API Overview 1–1
1.1.1 Scope and Portability 1–2
1.1.2 Events and Threading 1–4
2. Using Lightweight UI Toolkit Widgets 2–1
2.1 Component 2–1
2.2 Container 2–1
2.3 Form 2–2
2.4 Label 2–3
2.5 Button 2–5
2.6 RadioButton 2–6
2.7 ButtonGroup 2–7
2.8 CheckBox 2–8
2.9 ComboBox 2–10
2.10 TextArea 2–12
2.11 TabbedPane 2–13
3. Using Lists 3–1
iv Lightweight UI Toolkit Developer’s Guide • July 2009
3.1 Initializing a List 3–1
3.2 Creating a Model 3–2
3.2.1 ListModel 3–2
3.2.2 DefaultListModel 3–2
3.3 List Cell Renderer 3–3
3.3.1 ListCellRenderer 3–3
3.3.2 DefaultListCellRenderer 3–4
3.4 Adding Items to and Removing Items From a List 3–4
3.5 List Events 3–5
3.5.1 Fixed Selection Feature 3–5
3.5.2 Smooth Scrolling 3–6
4. Using Dialogs 4–1
4.1 Dialog Types 4–1
4.2 Creating a Dialog 4–2
4.2.1 Return Types of Show Methods 4–3
4.2.2 Non-Static Show Methods 4–4
4.2.3 Using the dispose() Method 4–4
4.2.4 Getting the User's Input from a Dialog 4–4
5. Using Layout Managers 5–1
5.1 BorderLayout 5–1
5.2 BoxLayout 5–3
5.2.1 X_AXIS 5–3
5.2.2 Y_AXIS 5–4
5.3 FlowLayout 5–4
5.4 GridLayout 5–6
5.5 GroupLayout 5–7
6. Using Painters 6–1
Contents v
7. Using the Style Object 7–1
7.1 Color 7–1
7.2 Font 7–2
7.3 Transparency 7–2
7.4 Margin and Padding 7–2
7.5 Images 7–3
7.6 Borders 7–4
7.7 Style Listener 7–4
7.8 Painters 7–4
8. Theming 8–1
8.1 Basic Theming 8–1
8.2 Look and Feel 8–4
9. Resources 9–1
9.1 Introduction 9–1
9.2 Resource Elements 9–1
9.2.1 Building a Bundle 9–2
9.2.1.1 Creating a Resource 9–2
9.2.1.2 Loading a Resource 9–2
9.2.2 Image Resources 9–2
9.2.3 Indexed Images 9–3
9.2.4 Fonts 9–4
9.2.4.1 System Font 9–4
9.2.4.2 Dynamic Fonts 9–5
9.2.5 Localization (L10N) 9–6
9.2.6 Themes 9–6
9.3 The LWUIT Designer 9–7
9.3.1 Images and Animations 9–9