Content area
Full Text
Swing is a collection of lightweight components built on top of the Java Abstract Windowing Toolkit (AWT). Swing components are based on the Light,eight UI Framework that became part of the Java AN&T with the JDK 1.1. (With JDK 1.2, Swing becomes part of the Java Foundation Classes.) Lightweight components do not have "peers" (platformdependent code) associated with them. They are thus unencumbered by problems brought on by peers, such as platformdependent bugs. Swing, which creates its components using pluggable look-and-feel modules written in pure Java, doesn't make use of native code. Pluggable look-andfeel lets an application running on heterogeneous platforms have the same lookand-feel across dissimilar machines. This feature also has the ability to change the visual representation of the application dynamically at run time.
As Figure 1 illustrates, the architecture of Swing components is based on the model-view-controller (MVC) paradigm. In a Swing component, models provide information that specifies the component's value, views manage the way in which the component and its data are drawn on the screen, and controllers modify the information maintained by the model in response to user input.
In actuality, Swing uses a modified MVC pattern, in which the view and controller are combined into a single component called the "delegate object." This reduces the number of communication paths between the model, view, and controller, and the number of components to be created and managed. In short, both the appearance and behavior of a component can be managed together, using just one delegate object. The delegate object encapsulates the look-and-feel of each Swing component.
JTable and Swing
In this article, I'll focus on JTable, one of Swing`s lightweight components, and explain how the MVC architecture applies to it. JTable is a view controller- it knows how to draw itself and acts as a controller for the various editors, with which it can be fitted for the Table data model. JTable is a user-interface component that presents data in a two-dimensional table format. Tables (or grids) implemented using JTable can be easily connected to databases through JDBC. JTable provides features such as reassessable and reorderable columns, a flexible and configurable row/column selection mechanism, cells that can be displayed using any components through the use of the Renderer interface (whereby...