| Previous | Table of Contents | Next |
JXTable Tutorial
A JXTable is an extension to the standard
Swing JTable adding support for runtime column selection,
background row highlighting, sorting and other features. A
JXTable can be used just like a JTable,
while allowing you to offer your users an extended feature set with
no additional coding.
This tutorial explains how to use a JXTable in your code. Each of the major features of JXTable is
explained with concise examples. This tutorial is based on a single sample program,
org.jdesktop.demo.sample.SampleJXTableDemo in the SwingLabs-Demos subproject.
Code samples shown here are taken from that class.
The extended features of JXTable are:
| Feature | What it does |
|---|---|
| Column Control | The JXTable introduces a small column control button, which opens a popup menu to configure the JXTable's display and behavior. The column control appears discretely to the right of the column headers. |
| Toggle Column Visibility | Users can select the columns they want to see on the JXTable by selecting the columns from the column control's popup menu; this can also be done programmatically. |
| Highlighting Rows | You can highlight rows in a JXTable by attaching a Highlighter. Highlighting allows you to easily distinguish between different rows, for example, every other row, using a subtle background color scheme. |
| Sorting Rows | JXTable has built-in support for row sorting at runtime, allowing the user to click on a column header and sort by that column. Using custom Comparators, you can determine the sorting rules that apply to different columns. |
| Filtering Rows | You can attach one or more filters to a JXTable, allowing you to control which rows are shown to the user. |
| Horizontal Scroll Control | With a single command, you can request that the table auto-resize to fit the viewport it's in, or to allow columns to scroll off to the right. |
| Resizing Columns | Users can auto-resize columns to fit their contents from the column control. |
| Previous | Table of Contents | Next |