The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Creating a GUI with JFC/Swing
Lesson: Using Swing Components

Using Swing Components: Examples (1.4)

The table that follows lists every 1.4 example in the Using Swing Components lesson, with links to required files and to where each example is discussed. The first column of the table has links to JNLP files that let you run the examples using JavaTM Web Start.

Version Note: Although these examples use the 1.4 API, many of them can be compiled and run in 1.3 if you remove the call to setDefaultLookAndFeelDecorated. To see earlier versions of most of these examples, go to the 1.1/1.2 example list (in the Creating a GUI with JFC/Swing trail).

To run an example using Java Web Start, click the [Run] link in the first column of the table. The first time you run an example, there will be a delay while Java Web Start downloads the JAR file containing the class files for this lesson's examples. Afterward, the examples should execute more quickly. If you have trouble using Java Web Start, see Installing and Using Java Web Start (in the Creating a GUI with JFC/Swing trail).

Compiling and Running the Examples Locally


Note: Examples are applications unless noted otherwise. See Getting Started with Swing (in the Creating a GUI with JFC/Swing trail) for details about releases and instructions on compiling and running programs.
You can get the source, image, and other files required for all these examples by downloading the Tutorial Examples bundle (outside of the tutorial), which contains the files in the correct hierarchy. If you download an individual example, take care to have all the necessary files in the proper hierarchy when you compile and run it. For example, many examples expect their image files to be in a directory named images that's in the same directory as the example's class files. Here's a typical setup:

Directory structure

You can find out which files each example needs by consulting the following table or by looking at the comments at the beginning of each source file.

Table of Examples

Example Source Files
(first file has the main method, except for examples that run only as applets)
Image and Other Files Where Described
ButtonDemo [Run] ButtonDemo.java (in a .java source file) right.gif, middle.gif, left.gif How to Use Buttons, ...
ButtonHtmlDemo [Run] ButtonHtmlDemo.java (in a .java source file) right.gif, middle.gif, left.gif How to Use Buttons, ...
CheckBoxDemo [Run] CheckBoxDemo.java (in a .java source file) All of the images in the images/geek directory. How to Use Buttons, ...
ColorChooserDemo [Run] ColorChooserDemo.java (in a .java source file)   How to Use Color Choosers
ColorChooserDemo2 [Run] ColorChooserDemo2.java (in a .java source file)
   CrayonPanel.java (in a .java source file)
red.gif, yellow.gif, green.gif, blue.gif How to Use Color Choosers
ComboBoxDemo [Run] ComboBoxDemo.java (in a .java source file) Bird.gif, Cat.gif, Dog.gif, Rabbit.gif, Pig.gif How to Use Combo Boxes
ComboBoxDemo2 [Run] ComboBoxDemo2.java (in a .java source file)   How to Use Combo Boxes
Converter [Run] Converter.java (in a .java source file)
   ConversionPanel.java (in a .java source file)
   ConverterRangeModel.java (in a .java source file)
   FollowerRangeModel.java (in a .java source file)
   Unit.java (in a .java source file)
  How to Use Panels;
Using Models
CustomComboBoxDemo [Run] CustomComboBoxDemo.java (in a .java source file) Bird.gif, Cat.gif, Dog.gif, Rabbit.gif, Pig.gif How to Use Combo Boxes
DialogDemo [Run] DialogDemo.java (in a .java source file)
   CustomDialog.java (in a .java source file)
middle.gif How to Use Dialogs
DynamicTreeDemo [Run] DynamicTreeDemo.java (in a .java source file)
   DynamicTree.java (in a .java source file)
  How to Use Trees
FileChooserDemo * FileChooserDemo.java (in a .java source file) Open16.gif, Save16.gif How to Use File Choosers
FileChooserDemo2 * FileChooserDemo2.java (in a .java source file)
   ImageFileView.java (in a .java source file)
   ImageFilter.java (in a .java source file)
   ImagePreview.java (in a .java source file)
   Utils.java (in a .java source file)
jpgIcon.gif, gifIcon.gif, tiffIcon.gif, pngIcon.png How to Use File Choosers
FormattedTextFieldDemo [Run] FormattedTextFieldDemo.java (in a .java source file)   How to Use Formatted Text Fields
FormatterFactoryDemo [Run] FormatterFactoryDemo.java (in a .java source file)   How to Use Formatted Text Fields
FrameDemo [Run] FrameDemo.java (in a .java source file)   How to Make Frames
FrameDemo2 [Run] FrameDemo2.java (in a .java source file) FD.jpg How to Make Frames
Framework [Run] Framework.java (in a .java source file)   Nowhere
GenealogyExample [Run] GenealogyExample.java (in a .java source file)
   GenealogyModel.java (in a .java source file)
   GenealogyTree.java (in a .java source file)
   Person.java (in a .java source file)
  How to Use Trees
GlassPaneDemo [Run] GlassPaneDemo.java (in a .java source file)   How to Use Root Panes
HtmlDemo [Run] HtmlDemo.java (in a .java source file)   Using HTML in Swing Components
InternalFrameDemo [Run] InternalFrameDemo.java (in a .java source file)
   MyInternalFrame.java (in a .java source file)
  How to Use Internal Frames
JWSFileChooserDemo [Run]

Note: This demo's Save button is disabled to avoid problems associated with bug #4761577 (outside of the tutorial).)
JWSFileChooserDemo.java (in a .java source file) Open16.gif, Save16.gif How to Use File Choosers
LabelDemo [Run] LabelDemo.java (in a .java source file) middle.gif How to Use Labels
LayeredPaneDemo [Run] LayeredPaneDemo.java (in a .java source file) dukeWaveRed.gif How to Use Layered Panes
LayeredPaneDemo2 [Run] LayeredPaneDemo2.java (in a .java source file) dukeWaveRed.gif How to Use Layered Panes
ListDemo [Run] ListDemo.java (in a .java source file)   How to Use Lists
ListDialogRunner [Run] ListDialogRunner.java (in a .java source file)
   ListDialog.java (in a .java source file)
  How to Use Buttons, ...
MenuDemo [Run] MenuDemo.java (in a .java source file) middle.gif How to Use Menus
MenuGlueDemo [Run] MenuGlueDemo.java (in a .java source file)   How to Use Menus
MenuLayoutDemo [Run] MenuLayoutDemo.java (in a .java source file)   How to Use Menus
MenuLookDemo [Run] MenuLookDemo.java (in a .java source file) middle.gif How to Use Menus
MenuSelectionManagerDemo [Run] MenuSelectionManagerDemo.java (in a .java source file) middle.gif How to Use Menus
PasswordDemo [Run] PasswordDemo.java (in a .java source file)   How to Use Password Fields
PopupMenuDemo [Run] PopupMenuDemo.java (in a .java source file) middle.gif How to Use Menus
ProgressBarDemo [Run] ProgressBarDemo.java (in a .java source file)
   LongTask.java (in a .java source file)
   SwingWorker.java (in a .java source file)
  How to Monitor Progress
ProgressBarDemo2 [Run] ProgressBarDemo2.java (in a .java source file)
   LongTask.java (in a .java source file)
   SwingWorker.java (in a .java source file)
  How to Monitor Progress
ProgressMonitorDemo [Run] ProgressMonitorDemo.java (in a .java source file)
   LongTask.java (in a .java source file)
   SwingWorker.java (in a .java source file)
  How to Monitor Progress
RadioButtonDemo [Run] RadioButtonDemo.java (in a .java source file) Bird.gif, Cat.gif, Dog.gif, Rabbit.gif, Pig.gif How to Use Buttons, ...
RootLayeredPaneDemo [Run] RootLayeredPaneDemo.java (in a .java source file) dukeWaveRed.gif How to Use Root Panes
ScrollDemo [Run] ScrollDemo.java (in a .java source file)
   Rule.java (in a .java source file)
   Corner.java (in a .java source file)
   ScrollablePicture.java (in a .java source file)
youngdad.jpeg How to Use Scroll Panes
ScrollDemo2 [Run] ScrollDemo2.java (in a .java source file)   How to Use Scroll Panes
SharedModelDemo [Run] SharedModelDemo.java (in a .java source file)
  Using Models
SimpleTableDemo [Run] SimpleTableDemo.java (in a .java source file)   How to Use Tables
SimpleTableSelectionDemo [Run] SimpleTableSelectionDemo.java (in a .java source file)   How to Use Tables
SliderDemo [Run] SliderDemo.java (in a .java source file) All of the images in the images/doggy directory. How to Use Sliders
SliderDemo2 [Run] SliderDemo2.java (in a .java source file) All of the images in the images/doggy directory. How to Use Sliders
SliderDemo3 [Run] SliderDemo3.java (in a .java source file) All of the images in the images/doggy directory. How to Use Sliders
SpinnerDemo [Run] SpinnerDemo.java (in a .java source file)
   SpringUtilities.java (in a .java source file)
   CyclingSpinnerListModel.java (in a .java source file)
  How to Use Spinners
SpinnerDemo2 [Run] SpinnerDemo2.java (in a .java source file)
   SpinnerDemo.java (in a .java source file)
   SpringUtilities.java (in a .java source file)
   CyclingSpinnerListModel.java (in a .java source file)
  How to Use Spinners
SpinnerDemo3 [Run] SpinnerDemo3.java (in a .java source file)
   SpringUtilities.java (in a .java source file)
   CyclingSpinnerListModel.java (in a .java source file)
  How to Use Spinners
SpinnerDemo4 [Run] SpinnerDemo4.java (in a .java source file)
   SpringUtilities.java (in a .java source file)
  How to Use Spinners
SplitPaneDemo [Run] SplitPaneDemo.java (in a .java source file) imagenames.properties and all of the image files listed in it. How to Use Split Panes
SplitPaneDemo2 [Run] SplitPaneDemo2.java (in a .java source file) imagenames.properties and all of the image files listed in it. How to Use Split Panes
SplitPaneDividerDemo [Run] SplitPaneDividerDemo.java (in a .java source file)
   SizeDisplayer.java (in a .java source file)
Cat.gif, Dog.gif How to Use Split Panes
TabbedPaneDemo [Run] TabbedPaneDemo.java (in a .java source file) middle.gif How to Use Tabbed Panes
TableDemo [Run] TableDemo.java (in a .java source file)   How to Use Tables
TableDialogEditDemo [Run] TableDialogEditDemo.java (in a .java source file)
   ColorEditor.java (in a .java source file)
   ColorRenderer.java (in a .java source file)
  How to Use Tables
TableFTFEditDemo [Run] TableFTFEditDemo.java (in a .java source file)
   IntegerEditor.java (in a .java source file)
  How to Use Tables
TableRenderDemo [Run] TableRenderDemo.java (in a .java source file)   How to Use Tables
TableSorterDemo [Run] TableSorterDemo.java (in a .java source file)
   TableSorter.java (in a .java source file)
  How to Use Tables
TableToolTipsDemo [Run] TableToolTipsDemo.java (in a .java source file)   How to Use Tables
TextComponentDemo [Run] TextComponentDemo.java (in a .java source file)
   DocumentSizeFilter.java (in a .java source file)
  Text Component Features
TextDemo [Run] TextDemo.java (in a .java source file)   How to Use Text Fields and How to Use Text Areas
TextInputDemo [Run] TextInputDemo.java (in a .java source file)   How to Use Formatted Text Fields
TextSamplerDemo [Run] TextSamplerDemo.java (in a .java source file) Pig.gif, sound.gif, dukeWaveRed.gif, TextSamplerDemoHelp.html Using Text Components and How to Use Editor Panes and Text Panes
ToolBarDemo [Run] ToolBarDemo.java (in a .java source file) JavaTM Look and Feel Graphics Repository (outside of the tutorial) (jlfgr-1_0.jar) How to Use Tool Bars
ToolBarDemo2 [Run] ToolBarDemo2.java (in a .java source file) Java Look and Feel Graphics Repository (outside of the tutorial) (jlfgr-1_0.jar) How to Use Tool Bars
TopLevelDemo [Run] TopLevelDemo.java (in a .java source file)   Using Top-Level Containers
TreeDemo [Run] TreeDemo.java (in a .java source file) Several html files. How to Use Trees
TreeIconDemo [Run] TreeIconDemo.java (in a .java source file) middle.gif and several html files. How to Use Trees
TreeIconDemo2 [Run] TreeIconDemo2.java (in a .java source file) middle.gif and several html files. How to Use Trees
TumbleItem [Run]

To run this as an applet (using JavaTM Plug-In): How to Make Applets (in the Creating a GUI with JFC/Swing trail)

To view the <APPLET> tag: TumbleItem.atag
TumbleItem.java (in a .java source file) (an applet)
   SwingWorker.java (in a .java source file)
All of the images in the images/tumble directory. How to Make Applets
* This application is not currently available with Java Web Start because we distribute only unsigned JAR files. To run it, download and compile it, and then run it as an application.

Geek Images

geek-----.gif, geek-c---.gif, geek--g--.gif, geek---h-.gif,
geek----t.gif, geek-cg--.gif, geek-c-h-.gif, geek-c--t.gif,
geek--gh-.gif, geek--g-t.gif, geek---h-.gif, geek-cg-t.gif,
geek-cgh-.gif, geek-c-ht.gif, geek--ght.gif, geek-cght.gif

Doggy Images

T0.gif, T1.gif, T2.gif, T3.gif, T4.gif, T5.gif, T6.gif,
T7.gif, T8.gif, T9.gif, T10.gif, T11.gif, T12.gif, T13.gif

Tumble Images

T1.gif, T2.gif, T3.gif, T4.gif, T5.gif,
T6.gif, T7.gif, T8.gif, T9.gif, T10.gif,
T11.gif, T12.gif, T13.gif, T14.gif, T15.gif,
T16.gif, T17.gif

Images listed in imagenames.properties


Note:  These files are used by
SplitPaneDemo and SplitPaneDemo2, which get the names of the images from a properties resource bundle backed by imagenames.properties. If you compile and run either program, put the imagenames.properties file in the same directory as the program's class files, and the image files in a subdirectory named images. The resource bundle contains a space-separated list of filenames that the program parses the into a Vector. You can learn more about resource bundles in Isolating Locale-Specific Data (in the Creating a GUI with JFC/Swing trail).

Bird.gif, Cat.gif, Dog.gif, Rabbit.gif, Pig.gif, dukeWaveRed.gif, kathyCosmo.gif, lainesTongue.gif, left.gif, middle.gif, right.gif, stickerface.gif

HTML Files Required for Tree Demos

TreeDemoHelp.html
arnold.html
bloch.html
chanlee.html
jls.html
swingtutorial.html
tutorial.html
tutorialcont.html
vm.html

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.