Recent articles:
Popular archives:
Java: A platform for platforms
Sun's reorg may seem promising to shareholders but it's also a scramble for position. The question now is whether Sun can,
or wants to, maintain its hold on Java technology. Especially with enterprise leaders like SpringSource and RedHat investing
heavily in Java's future as a platform for platforms
Also see:
Discuss: Tim Bray on 'What Sun Should Do'
In an enterprise or application service provider (ASP) environment, the console provides a window into a system's operation and allows operators to configure and control the system in real time. The console can also display unprompted status information and announcements.
In this article, I'll show you how to construct a generic console from Swing components that uses the Java Messaging Service (JMS) to interact with one or more application subsystems. JMS provides a standard solution to the problem of communication between the backend system's command servers and their clients.
Figure 1 shows the console client's on-screen appearance. The user types commands in the interface's lower box (JTextField) and receives an answer in the text area above it. The dot before the command indicates that the command goes to the console
itself rather than to the connected host or queue. When text fills the text area, scroll bars automatically appear.

Figure 1. The console in action with the default Metal look and feel
Rather than create a distributed communication system in one step, we will build up to the finished product in stages. First, we will construct a basic console that operates synchronously using a socket. This introduces the Swing fundamentals and demonstrates how to build a functional console without the extra JMS complexities. Then we will extend our basic console with useful features, such as tabbed panes. Finally, we will add JMS for industrial-strength communications.
The biggest hurdle to starting with Swing is understanding its underlying object model. Your application or applet must sit above a complex web of classes with subtle and hidden interactions. Later in this article, I will cover some other important topics, such as event threads and peers. To get started, you just need to know the component model. Mastering this foundation takes time, but the inheritance outline below may give you a leg up on the learning curve:
Swing's inheritance model
java.awt.Component (abstract)
java.awt.Container
javax.swing.JComponent (abstract)
javax.swing.JRootPane
...other concrete components (JPanel, JTree etc.)
java.awt.Window
java.awt.Panel
java.applet.Applet
javax.swing.JApplet
javax.swing.JWindow
java.awt.Dialog
javax.swing.JDialog
java.awt.Frame
javax.swing.JFrame
The top-level Swing components (JApplet, JWindow, JDialog, and JFrame) are in bold above. Each of these containers has only one component, JRootPane. The diagram below illustrates the JRootPane -- the key to Swing.

Figure 2. The organization of Swing's JRootPane
The root pane has a glass pane on top and a layered pane underneath. The layered pane is composed of a MenuBar and a ContentPane. You add subcomponents to your outer container via the content pane. When you use a component's getContentPane() method, you are actually getting its root pane's content pane.