Trail: Creating a GUI with JFC/Swing
Lesson: Using Swing Components
Using Swing Components: Examples
The table that follows lists every 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.


NOTE: Release 6.0 is required to run all applets and Java Web Start examples. Most examples will run on an earlier release but you must compile and run them locally.

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.

Compiling and Running the Examples Locally


Note: Examples are applications unless noted otherwise. See Getting Started with Swing 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, 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 right.gif, middle.gif, left.gif How to Use Buttons, ...
ButtonHtmlDemo [Run] ButtonHtmlDemo.java right.gif, middle.gif, left.gif How to Use Buttons, ...
CheckBoxDemo [Run] CheckBoxDemo.java All of the images in the images/geek directory. How to Use Buttons, ...
ColorChooserDemo [Run] ColorChooserDemo.java   How to Use Color Choosers
ColorChooserDemo2 [Run] ColorChooserDemo2.java
   CrayonPanel.java
red.gif, yellow.gif, green.gif, blue.gif How to Use Color Choosers
ComboBoxDemo [Run] ComboBoxDemo.java Bird.gif, Cat.gif, Dog.gif, Rabbit.gif, Pig.gif How to Use Combo Boxes
ComboBoxDemo2 [Run] ComboBoxDemo2.java   How to Use Combo Boxes
Converter [Run] Converter.java
   ConversionPanel.java
   ConverterRangeModel.java
   FollowerRangeModel.java
   Unit.java
  How to Use Panels;
Using Models
CustomComboBoxDemo [Run] CustomComboBoxDemo.java Bird.gif, Cat.gif, Dog.gif, Rabbit.gif, Pig.gif How to Use Combo Boxes
DialogDemo [Run] DialogDemo.java
   CustomDialog.java
middle.gif How to Use Dialogs
DynamicTreeDemo [Run] DynamicTreeDemo.java
   DynamicTree.java
  How to Use Trees
FileChooserDemo * FileChooserDemo.java Open16.gif, Save16.gif How to Use File Choosers
FileChooserDemo2 * FileChooserDemo2.java
   ImageFileView.java
   ImageFilter.java
   ImagePreview.java
   Utils.java
jpgIcon.gif, gifIcon.gif, tiffIcon.gif, pngIcon.png How to Use File Choosers
FormattedTextFieldDemo [Run] FormattedTextFieldDemo.java   How to Use Formatted Text Fields
FormatterFactoryDemo [Run] FormatterFactoryDemo.java   How to Use Formatted Text Fields
FrameDemo [Run] FrameDemo.java   How to Make Frames
FrameDemo2 [Run] FrameDemo2.java FD.jpg How to Make Frames
Framework [Run] Framework.java   Nowhere
GenealogyExample [Run] GenealogyExample.java
   GenealogyModel.java
   GenealogyTree.java
   Person.java
  How to Use Trees
GlassPaneDemo [Run] GlassPaneDemo.java   How to Use Root Panes
HtmlDemo [Run] HtmlDemo.java   Using HTML in Swing Components
InternalFrameDemo [Run] InternalFrameDemo.java
   MyInternalFrame.java
  How to Use Internal Frames
JWSFileChooserDemo [Run]

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

To view the <APPLET> tag: TumbleItem.atag
TumbleItem.java (an applet)
   SwingWorker.java
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.

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:
Next page: