Swing : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

Swing Swing
Oracle’s set of lightweight GUI (Graphic User Interface) components that give much fancier screen displays than the raw AWT (Advanced Windowing Toolkit). Since they are written in pure Java, they run the same on all platforms, unlike the AWT. They are part of the JFC (Java Foundation Classes). They support pluggable look and feel — not by using the native platform’s facilities but by roughly emulating them. This means you can get any supported look and feel on any platform. The disadvantage of lightweight components is slower execution. The advantage is uniform behaviour on all platforms.
Gotchas Difference Between Window Types
Swing Threads Books
AWT vs Swing Learning More
Converting AWT to Swing Links

Gotchas

The biggest gotcha is that you no longer add directly to your Swing containers. Any content inside a JFrame should be placed inside its contentPane. You must do a:
Container pane = swingContainer.getContentPane();
and add to it. Unfortunately the add method is still defined for the Swing Containers to entrap the unwary.

In Swing, override JComponent.paintComponent instead of paint.

Swing’s JComboBox is misnamed. It does not let you select a combination of choices. It is a combination Choice and write-in TextField allowing the user to add new possible choices on the fly. Swing classes live in package javax.swing.*. They used to live in com.sun.java.swing.*.

FormattedTextField does not verify input the way you might expect. To learn how to do that you need to read up on

and 

The good news is, even though you are using Runnable, you don’t have the overhead of actually creating a new Thread since you are just calling the run method on the already existing Swing Thread.

You are not on the Swing event thread when main first starts up! You are on it in your event listeners. You are tell if you are on it with:

One of the most common errors is to tie up the AWT/Swing event thread with some long running computation or even a sleep. Everything freezes up. The GUI can’t respond to mouse clicks and no repainting happens. You have to spin the time-consuming task off on its own thread or use a Timer.

is a Sun class that is not part of the JDK (Java Development Kit). It lets you convert some long-running event handling code into a separate thread with just a line of extra code.

If you violate these rules, the entire system starts to behave unpredictably and irrationally. If by violating these rules, you manage to create two event-processing threads, life gets really interesting as they unpredictably fight with each other handling Swing events.

AWT vs Swing

Which should you use, AWT or Swing?

Roughly Equivalent Components in AWT and Swing
AWT Swing Purpose
Applet JApplet Run inside a browser.
none Border decorate with a fancy edge.
Button JButton User clicks button to make something happen.
Canvas JPanel or JLayeredPane Place to roll your own low-level drawing
Checkbox JCheckBox (checked) or JRadioButton (round) or JToggleButton (full button) Checkbox is a small box, the user can tick or not to indicate a desired option. A RadioButton displays as a round button. JToggleButton displays as a rectangular button, usually with a custom icon. By default, the background changes colour slightly when selected. You can use these in isolation, or in clusters controlled by a CheckboxGroup or ButtonGroup.
CheckboxGroup ButtonGroup Used in conjunction with Checkbox, JCheckBox, JRadioButton and JToggleButton to allow only on of group of options to be selected.
Choice JComboBox Allows user to pick one from a drop-down menu of choices. JComboBox has a write-in feature. Ironically, JComboxBox does not support combinations of choices. For that you need a java.awt.List or JList.
Color Color Describes a colour with 8 bits each of red, green, blue and transparency.
none JColorChooser Let’s user choose a colour from a palette, or numerically, but not using hex.
Component JComponent Used to roll your own widgets.
Container Container Used to manage the Chinese boxes of panels within panels.
Dialog JDialog or JOptionPane Pop up a box to ask the user a question. JOptionPane is a simplified JDialog to handle common cases.
FileDialog JFileChooser Let the user select a directory or file from a tree.
none JFormattedTextField Let the user key in a field where certain characters must be alphabetic or numeric.
Frame JFrame or JInternalFrame Normal top level moveable window with widgets on it for minimize and close.
Label JLabel Used to label fields. Displays text. User cannot type into it. It tends to blend into the background.
List JList + JScrollPane JList lets the user make a selection, or many selections from a presented list which is always expanded. For long lists, you scroll. See also JComboBox
LayoutManager LayoutManager Lets you design your layouts so they automatically reflow with different amounts of screen real estate, different text, difference translations, different available fonts etc.
Menu with MenuBar and MenuItem JMenu with JMenuBar, JMenuItem, JRadioButtonMenuItem and JPopupMenu Drop down menus to select functions to perform. JRadioButtonMenuItem allows toggling option selections in the menus. JPopupMenu lets the user pop up a menu when she right clicks a component.
Panel JPanel or JToolBar or JSplitPane or JTabbedPane, or JLayeredPane. Panels collect components together into rectangles to simplify layout and enable encapsulation. A panel can be treated like an atomic component for most purposes. JToolBar is just a panel specialised for holding a row of buttons. JSplitPane is a split panel where the user can move the divide. JTabbedPane lets you cram many panels in small space. The user selects a tab, much as on a file folder, to bring one of them into full view. JLayeredPane is an advanced feature for composing transparent overlays, e.g. sprites.
none JPasswordField For entering passwords.
ScrollPane JScrollPane For scrolling a panel where there is not enough room to see it all at once.
none JSeparator A decorative horizontal or vertical line. Note the spelling: JSeparat or.
none JSlider The user uses the mouse to move an analog slider to select a value.
none JSpinner The user uses arrow keys or a mouse to select a value by making it go higher or lower.
TextArea JTextArea or JEditorPane or JTextPane TextArea and JTextArea allow multi-line text display and data entry. JEditorPane allows display of formatted HTML (Hypertext Markup Language) or RTF (Rich Text Format) with colours and fonts whereas JTextPane is like JEditorPane with the additional ability to edit styles and character attributes.
TextField JTextField Allow display or entering of one line of unformatted text. They always have a box around the text unlike labels which blend into the background. For more than one line see TextArea and JTextArea.
none JTable
none JTree Displaying and editing tree-structured data.
Window JWindow Like a frame without the top bar widgets.

Converting AWT to Swing

There is more to flipping from AWT to Swing that putting a J in front of the component names. One biggy is figuring out where to use contentPanes. Don’t forget to change paint to paintComponent. You have to decide how to setOpaque. There is not much point in flipping to Swing unless you take advantage of the new features: e.g. wider range of fonts, margins, JSliders, JSpinners and JTables. If Oracle ever fixes the bugs, you might want to use the more advanced formatting available with HTML in JLabels and JEditorPanes. You might want to tackle it a class at a time or you may find yourself stuck in a middle of a very long conversion with nothing working.. One technique is to use is a search/replace script, based on your manual experience with a few classes, then compile, patch the errors, the eyeball for gotchas.

Difference Between Window Types

What are the differences between a Applet, Canvas, Component, Container, Dialog, Frame, JApplet, JComponent, JContainer, JDialog, JInternalFrame, JPanel, JFrame, JWindow, Panel and Window?

When the following table suggests a Component is for AWT but not Swing, it means there is an improved Swing component. In theory you could use the old AWT component, but normally you would not want to.

When it asks if Components are visible, it means, are the visible by default when first created. Obviously you set do a setVisible( true ) later. The rule of thumb is, freestanding windows start out invisible and everything else starts out visible. Another way of looking at it is, everything derived from Window starts out invisible.

The paned refers to whether you use getContentPane.setLayout or simply setLayout.

Differences Between Various Types of Windows
class What Is It AWT Swing Visible Paned Derived From Default Layout
Applet represents the featureless Window provided by the browser for an Applet to run in. Panel FlowLayout
Button Not a window. It is here is an example of a Component. Component n/a
Canvas an area you can use the low level drawing tools on, rather than dropping in components placed with a LayoutManager. Raw material for creating your own components. Just a place you can draw. It cannot contain Components. For Swing, use a JPanel instead. Component n/a
Component Not a window. It is an abstract class underlying Buttons etc. Object n/a
Container These are the basis on which all the other windows are built. They manage the child Components and LayoutManager. They are missing an addNotify method to create the peer object, so can’t appear on screen. You don’t normally instantiate Containers directly, but some subclass of them. Component null
Dialog A pop-up box to deliver an error message or alert. Temporary Window for displaying information or requesting keystrokes. It requires a parent Frame, thus in cannot be used inside an Applet which has no Frame. It can be modal, which means it blocks input to all other Windows until it is dismissed. It must have a Frame mentioned in the constructor. Window BorderLayout
Frame A resizable, movable window with title bar and close button. Usually it contains Panels. Window BorderLayout
JApplet represents the featureless Window provided by the browser for an Applet to run in. Applet FlowLayout
JButton Not a window. It is here is an example of a JComponent. AbstractButton, JComponent n/a
JComponent Not a window. It is an abstract class underlying JButtons etc. Container, not Component, Container! n/a
JContainer There is no such beast! Since Containers have no on screen aspect, the ordinary AWT Container suffices. n/a n/a n/a n/a n/a n/a
JDialog A pop-up box to deliver an error message or alert. Usually created with JOptionPane methods. Temporary Window for displaying information or requesting keystrokes. It requires a parent JFrame, thus in cannot be used inside an JApplet which has no JFrame. It can be modal, which means it blocks input to all other JWindows until it is dismissed. You can place complex arrays of Components on JDialogs, not just simple error messages. Dialog BorderLayout
JFrame A resizable, movable window with title bar and close button. Usually it contains JPanels. The entire application is usually a JFrame. Frame BorderLayout
JInternalFrame Independent windows that the user can resized and move, but only within an enclosing JFrame. JComponent BorderLayout
JOptionPane A modal pop-up box to deliver an error message or alert. Temporary Window for displaying information or requesting keystrokes. It requires a parent JFrame, thus in cannot be used inside an JApplet which has no JFrame. Unlike a JDialog, JOptionPanes are always modal, which means they block input to all other JWindows until they are dismissed. JDialog BorderLayout
JPanel A region internal to a JFrame or another JPanel. Used for grouping components together. Optionally bounded by a visible border. Lives inside some enclosing Container. JComponent FlowLayout
JWindow A window without a title bar or move controls. The program can move and resize it, but the user cannot. It has no border at all. It optionally has a parent JFrame Window BorderLayout
Panel A region internal to a Frame or another Panel. Used for grouping components together. Not bounded by a visible border. You can change background colour of a panel to delimit it though. Lives inside some enclosing Container. Container FlowLayout
Window A window without a title bar or move controls. The program can move and resize it, but the user cannot. Free standing Window, not inside any other Window. It must have a parent Frame mentioned in the constructor. Container BorderLayout

For a great overview what is possible with Swing, see the SwingSet2 demo that comes part of the JDK download. Run

cd %JDK64\demo\jfc\swingset2]
java -ea -jar Swingset2.jar

Books

book cover recommend book⇒Swing Hacks: Tips and Tools for Killer GUIsto book home
by Joshua Marinacci & Chris Adamson 978-0-596-00907-6 paperback
publisher O’Reilly recommended
published 2005-06-01
Weird, fun, tricky, non-obvious things you can do with Swing.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Swing, second editionto book home
by Matthew Robinson, Pavel Vorobiev, David Anderson 978-1-930110-88-5 paperback
publisher Manning 978-0-613-91418-5 hardcover
published 2003-02
A relatively deep book. Also covers printing.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Java Swing, second editionto book home
by James Elliott, Robert Eckstein, Marc Loy, David Wood, Brian Cole 978-0-596-00408-8 paperback
publisher O’Reilly recommended 978-1-4493-3730-8 eBook
published 2002-11-01 B007Y6KIHI kindle
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Professional Java Custom UI Componentsto book home
by Kenneth F. Krutsch, David S. Cargo, Virginia Howlett 978-1-86100-364-5 paperback
publisher Peer Information
published 2001-08
How to write your own AWT and Swing Components. The book is a bit long in the tooth, so gives most emphasis to AWT.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Core Swing Advanced Programmingto book home
by Kim Topley 978-0-13-083292-4 paperback
publisher Pearson Education
published 1999-12-20
On reading the Amazon reviews, this book looks best for HTML rendering.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒John Zukowski’s Definitive Guide to Swing for Java 2 with CD-ROMto book home
by John Zukowski 978-1-893115-02-6 paperback
publisher Apress B00ACC5F7E kindle
published 1999-06-15
very clear writer
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.

Learning More

Oracle’s Javadoc on Swing component summary package : available:
Oracle’s Javadoc on AWT component Summary package : available:

This page is posted
on the web at:

http://mindprod.com/jgloss/swing.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\swing.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.135.204.43]
You are visitor number