The Table Editing Process How It Works

Java > Core SWING advanced programming > 6. CREATING CUSTOM TABLE RENDERERS > Summary

 

Summary

We started this chapter by examining how table cell renderers work and how the table selects the renderer to be used as it draws each cell and we illustrated this by showing a table containing, among other things, currency exchange rates. To demonstrate how simple it is to create a basic renderer, we showed how to improve the presentation of the exchange rates in the table by implementing a renderer that displays a numeric value with a (configurable) fixed number of decimal places. Having seen the basic mechanism, which is column-based, we moved on to describe the technique of renderer cascading which allows you to apply extra effects to a table that the original cell renderers do not supply, without having to modify or subclass them. One simple, but effective, use of renderer cascading is adding row-based effects such as colored stripes by changing the background color of alternate rows of the table. A natural progression from here is to use the layered rendering technique to control rendering at the cell level instead of on a row or column basis. The table also provides a more direct way to get specific effects in individual cells, although you need to subclass JTable and override its getCellRenderer method to use this mechanism.

Custom renderers can also be used to provide sophisticated table column headers, one example of which is a heading containing more than one line of text. The same technique can, as we showed, also be used to provide the same feature in the table cells themselves. Finally, we showed how to arrange for the table's tooltips to depend on the content of the cell that the user places the mouse on.

 

 



Core Swing
Core Swing: Advanced Programming
ISBN: 0130832928
EAN: 2147483647
Year: 1999
Pages: 55
Authors: Kim Topley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net