Thursday, 12 June 2008

Swing Table with frozen columns part I

I have long wanted to have the feature of frozen columns in a Swing grid. I have been working on my spare time on an electronic trading user interface lately, and from my experience in the investment banking industry, I have noticed the simple following points:

  • If the user interface sucks, the user (trader) usually thinks that the whole system sucks

  • People (managers, developers) always under-estimate the user interface

  • The user interface is the most complex part of the system: it has to perform, look good and be flexible

In this series, I will show you my personal interpretation of what an E-Trading User Interface should look like.

Whether you go for NetBeans Modules, or Eclipse RCP, or write your own small framework that meets your needs, keep in mind the word “simplicity”.

Now… Collin Fagan gave us the code to hack Swing in order to display a JTable with frozen columns. You can find his code for the NonScrollingColumnsDemo here

I have used the ideas from his demo and the JXTable component from SwingX to use the column control (top-right hand corner of the table) to add the ability to add, remove frozen columns and visible columns to a grid. I call this new grid a SuperGrid because it is composed of two JXTables, the left one being the frozen grid, the right one being the normal grid where the horizontal scroll is displayed.

Follows a snapshot of the super grid (note the button on the top-right hand corner, the one with the question-mark as an icon):

There is nothing exciting here, but now if you click on the button, you should see something like:

There are two menus, a “Visibility” menu and a “Frozen” menu.
By selecting a column in the menus, you can make a column visible or not, frozen or not (moved to the left or to the right).

This is really useful as you can decide at runtime which columns to display. Each column is backed up by a config that is persisted with the column state: visible, frozen, width so that next time you start the application, the previous layout is restored.

The code is available on demand. A Web-started version will be there for you soon. The most interesting part will be the trading application!

1 comment:

Vandyke said...
This comment has been removed by the author.

Blog Archive