Tuesday Aug 19, 2008

Sakila and "org.netbeans.swing.etable.ETable"

I read about the Sakila sample database in James' blog and thought it a good opportunity to try out the new "ETable" component. "ETable? What's that?" you might be wondering. ETable is a Swing component that extends JTable (hence the "E" for "extension"). It was created by Nokia in 2003 when David Strupl worked there as a freelancer. David is now back in the NetBeans engineering team and the ETable is part of the NetBeans Platform, within the "org-netbeans-swing-outline.jar" in "platform9".

Here it is in action, notice that one can sort (for which I needed to do no coding whatsoever) and that there's a dialog that can be used to hide columns that you, as the end user, don't want to see (no coding for that either):

The data is from the aforementioned Sakila database. (I did no coding whatsoever to create the small app above, just dragged the ETable onto the JFrame and then dragged the table from the Services window into the ETable.)

You're able to prevent the hiding of columns very simply, like this:

eTable1.setColumnHidingAllowed(false);

So what does the "ETable" provide, exactly, i.e., aside from the above briefly mentioned features? Broadly, David told me that they created this component based on features that Excel spreadsheets provide. I.e., they looked at Excel spreadsheets and thought: "Wouldn't it be cool if we had these features in our own tables?" So, the ETable is inspired by Excel's features, in particular those that were missing in the JDK 1.4 (i.e., 2003) JTable. In addition, David told me they decided to base the tree-like features on Tim Boudreau's Outline component.

Here are some further notes on the feature candidates for the ETable (most of these are implemented), which are portions of 2003 e-mails between David Strupl and the developers from Nokia.

  • Properties support, i.e., the table should have an API to find out the properties of the displayed object and render the table columns dependent on that.
  • Column selection, i.e., there should be a selection dialog for selecting the visible table columns (based on the properties model).
  • Popup menus, i.e., table rows should display popup menus for the selected objects (based on enode functionality).
  • Sorting, possibly also multi-way.
  • Improved layouting, i.e., Sensible initial layout based on data content.
  • Possibility to persist the layout.
  • Double-click/ctrl-+ sizing of columns.
  • Fixed first column (i.e., doesn't scroll along horizontally).
  • Categorization/tree table functionality (i.e., hierarchy API).
  • Keyboard jumping/quick find? (I.e., hit a key/set of keys to jump to a particular line of the table.)
  • Quickfilter? (I.e., show only rows with a particular value in a column).

Here's multisort in action. First, I click the header of the Last Name column and then the values are sorted alphabetically:

Next, I hold down the shift key and then click the header of the First Name column:

Now look above at the First Name column and notice that they're alphabetical, within the alphabetical-sort of the Last Name column.

Next, we'll look at the Quickfilter mentioned in the list above. I simply type this:

eTable1.setQuickFilter(1, "AKROYD");

And then the result is like this:

Various other customizations are possible. For example, do you like the ability to hide the columns, but not the dialog for doing so? Add one extra statement to your code:

eTable1.setPopupUsedFromTheCorner(true);

Then you'll have a small popup, instead of the dialog, for hiding columns, like this:

How to get started with "ETable"? Simply add "org-netbeans-swing-outline.jar" from "platform9" to your app's classpath. Then browse to it via the Palette Manager and add the "ETable" to the Palette so that you can drag it into your Swing containers from there.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« August 2008 »
SunMonTueWedThuFriSat
     
2
4
5
6
7
11
14
17
20
23
27
29
30
31
      
Today