The ShowBean Program

We began this chapter using the ShowBean program to experiment with Swing components, and with the custom components developed as examples. As promised, the implementation is here in Example 11-30. This is another example of a Swing application that uses JFrame, JMenuBar, and so on. It uses the LookAndFeelPrefs utility class from Example 11-29, demonstrates the JTabbedPane component, and shows the use of tooltips in Swing.

ShowBean relies on the Bean class of Example 15-10. This class provides the JavaBeans magic for listing, querying, setting, and invoking bean properties and commands. You’ll have to skip ahead to Chapter 15 if you want to see how that piece works.

ShowBean also has a feature that was not mentioned before: in addition to creating beans based on their classname, it can also read beans that have been serialized to a file using the serialization mechanism or the (new in Java 1.4) JavaBeans persistence mechanism. Use the -ser or -xml options on the command line to create a bean from a file. Additionally, the File menu contains entries that allow you to save a bean (and its currently set properties) to a file using either serialization or the JavaBeans persistence mechanism.

Example 11-30.

package je3.gui; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.beans.*; import java.lang.reflect.*; import java.util.List; // explicit import to disambiguate from java.awt.List import ...

Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.