|
|
Scrolling a Table
As was seen in Chapter 3, JComponent, the JComponent class defines the autoscrolls property. In the JComponent class, the default value for this property is defined to be false. However, the JTable class overrides the value for this property and sets it to true. This allows large tables contained in a JScrollPane instance to be scrolled both horizontally and vertically by dragging the mouse in the desired direction. The scrollbars do not need to be used. Currently in the JFC, the JList and JTable classes are the only two classes that take advantage of this functionality.
Summary
The JTable class uses a complex collection of interfaces and classes by delegating much of its functionality to support classes. This requires understanding how interfaces and classes work and how they interact with one another to fully understand how the table component works. The immaturity of these interfaces and classes is apparent in the inconsistency of implementation of interrelated classes and the small number of bound properties in the JTable class. These inconsistencies raise the bar on the learning curve for effectively using the Table package.
This chapter doesnt present every method contained in the JTable class or the classes in the table package. However, the most common methods, and those required for customization, are presented here. The complete API for all these classes is given in the reference section.
The current set of default renderers and editors for the JTable class is very limited. This chapter showed how to create a renderer and an editor for the Color class, as well as enhancing the existing renderers for the Boolean, Number, String, and Object classes. As the JFC matures, you can remain hopeful that a rich collection of renderers and editors will be provided from the toolkit. Obvious omissions other than the Color class are the Date class and editors that verify Numbers.
A complex example was presented that contained a custom data model, custom data renderers, and editors. After understanding this example, you should be equipped with the tools required to create tables of arbitrary complexity.
|