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.

Comments:

Any chance you guys could extract it out of NB and just make it a stand-alone component or add it to SwingX?

Posted by Jacek on August 20, 2008 at 12:18 AM PDT #

SwingX already has JXTable which does essentially the same as far I can tell (+ highlighting). Same story as with Outline vs. JXTreeTable. It would be nice if these could be consolidated.

Posted by Casper Bang on August 20, 2008 at 12:35 AM PDT #

Thanks again Geertjan for these snippets.

I'm currently trying to write an 'how to build GUIs in Java' and have to say that
GUI building in Java still sucks. I can't believe that there's still no standard widget toolkit and
a decent application framework the JDK comes with.

Yes, there's Swing. And yes, there's matisse and it's awesome NetBeans integration.
But that's it, isn't it? When it comes to 'how do I? ...', you will instantly see yourself grabbing numerous
libs from the web to get your things done. Even the Swing App Framework is not ready to be delivered with the JDK. You'll have to find it yourself - or use NetBeans, of course.

That's the reason why the majority of Java GUIs simply are no pleasure to use at all - it's way to hard
to develop them. You need to be the Roman Guy type of developer to develop awesome looking Swing
GUIs (ever had a look into 'Filthy Rich Clients'?).

Swing's initial goal to copy the VB approach of GUI building (combined with JavaBeans and a corresponding IDE)
is still not reached - IMHO.

Sad. But I really appreciate the work of all the folks trying to improve things for us 'consumers'!

Marcus

Posted by Marcus Olk on August 20, 2008 at 05:40 PM PDT #

Marcus, I agree with you. Unfortunately it seems the problems are being addressed very indirectly.

Matisse/GroupLayout:
While definitely a much better working LayoutManager than any previous ones, it relies on a separate XML file as well as locking down stuff in the code. So if you added your event handling through the NetBeans UI, good luck in maintaining or refactoring it - because you can only do so by going behind NetBeans back. The ideal would have been if full and open round-trip engineering would've worked between Matisse and code views without needing to lock stuff and without external meta files (C# and VB demonstrated this is doable).

Lack of components:
Swing has no real component model. Properties exist only when you reflectively inspect is/get/set methods and events are hidden behind interface callback dispatch, meaning we often need inner classes and adapters (this might be the reason why Matisse feels compelled to lock everything down).
It makes component authoring, discovery and reuse difficult. Notice for instance how the extremely widely used JFreeChart can't be used as a component inside NetBeans or how to this day, we still have to go hunt for a DatePicker for our project we then hope behaves nicely with regard to L&F & i18n issues. There's is a distinct lack of a "component marked" compared to i.e. Flex or .NET.

JavaFX > Swing:
Unfortunately I don't think these issues are being solved. SUN created a new language (JavaFX) instead and as you probably know, the closure war is raging stealing the spotlight for many other improvements in the Java language like properties and events. JavaFX is the reason JSR-296 (the desktop stuff) went dead for almost ½ year and the spec lead has now actually left SUN. So I do fear JavaFX won't exactly help on making Swing better.

Sorry about the rant, that's what happens when you open your mouth before the morning coffee. I too really appreciate the work being done.

Posted by Casper Bang on August 20, 2008 at 09:39 PM PDT #

I have just started using the swingx JXTable and this seems very similar.

I would be nice for some of these components to make it into the jdk. It's a shame that the basic JTable's functionality is so far behind what users expect from a table's behaviour. After all the default JTable is what a lot of people will be using when starting out with swing. It seems like there are a lot of quite mature components out there in the Open source but sun is spending more time writing JavaFX than enhancing the swing components.

My question now is JXTable or ETable?

thanks for the post.

Posted by Andre Parodi on August 21, 2008 at 08:18 PM PDT #

Marcus, please check out my Java SwingBuilder project:
http://javabuilders.org

It \*does\* solve all the Swing pain points. At least that's what the folks using it have been telling me :-)

And no, we don't rely on GroupLayout. It's MigLayout all the way...everything else is a joke compared to that.

Posted by Jacek Furmankiewicz on August 21, 2008 at 11:14 PM PDT #

Those rants about Swing/Java are from an old world.
Swing (and Java) are the way they are with choice of external libraries certainly because developers asked it that way. And it works ! If you don't want to choose your components you could just pay for excellent ones. See Jide for example.

By the way, JBuilder and Visual Age had all VB-like functionality (they were commercial IDEs as Microsoft's ones). You could also choose one of modern commercial Java IDEs if you like. Me, I prefer Eclipse/NetBeans with Swing.

It is my understanding that with Microsoft you have far less than Eclipse/NetBeans if you don't pay.

Posted by evernat on September 02, 2008 at 08:12 PM PDT #

To the comment "Swing has no real component model."
Hmmm... most components have a model. A JTable has a TableModel, a JTree has a TreeModel, a JButton has a ButtonModel, a JComboBox has a ComboBoxModel. Which components don't have a model?

To evernat: so let me get this straight: I'm supposed to develop my GUIs in YAML? I have custom vector icons, and I'm also using the NB visual api (with custom widgets, custom events, context specific popups that change depending on selection state, etc..), is all this now better when I wrap it in YAML? Maybe only for "lowest common denominator" applications, but I don't care about those.

To Furmankiewicz: so Mig Layout is better than the layout built into NB?
I would challenge that. I've used both (MigLayout by hand, and NB from the GUI). From a hand-coding perspective the two technologies are comparable, but who needs hand coding when you have NB? If you look at the whole picture, I contend that NB GUI designer is superior to all other alternatives (for Swing building), and this by a considerable margin.

To Casper: yes I think you are a bit right when you say you need to be the "Roman Guy" type of developer to make good GUIs. I don't believe that world class GUIs can be created in any technology, however, without a lot of experience in that specific GUI toolkit and a lot of experience in GUIs in general (you need to understand graphics, user interaction, application organization, etc...)

Also, you wrote "the majority of Java GUIs simply are no pleasure to use at all ".
Sadly, this is often true. However, for most of the applications I have seen that use Swing (including all the thousands of Applets) there are no other programs at all (in any GUI technology or any language, good or bad) that do the same thing.

Posted by recogic on March 09, 2009 at 07:22 PM PDT #

I meant the previous comment w.r.t. YAML to be a response to Furmankiewicz, not evernat, sorry.

Posted by recogic on March 09, 2009 at 08:00 PM PDT #

Where is an example how to persist the layout (columns width, order, visibility)?
I've googled a lot, but nothing found.

Posted by cencio on September 03, 2009 at 07:46 AM PDT #

Dear Sir,

I would like to JCombobox render is cell. Could you please give me an example source how can i do this.

Posted by Ismail on November 10, 2009 at 04:34 PM PST #

can we add columnSelectorpane without having jscrollpane in etable

Posted by manish on November 19, 2010 at 05:03 AM PST #

can u plz help me with how to make searching of the data from d table possible

Posted by manish on November 21, 2010 at 10:05 PM PST #

Hi Geet,

In your article you have a mention about 'Fixed first column (i.e., doesn't scroll along horizontally).' etable feature.

Can you put some more light on its current status? Is it implemented? If yes, which version of platform has this feature..

Thnx.

Posted by Anup on January 11, 2011 at 06:06 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
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
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today