JTable: Time to Rethink NIH?

You know what Not Invented Here (NIH) means, Google it if you need help. I’m here to talk about one case where we may need more innovation: Swing’s JTable component.

Background

I really like JTable. JTable is a remarkably powerful GUI component, accommodating a huge spectrum of applications. Its design provides clear separation between the table, scroll pane, table header, cell renderers, cell editors, and the table model. The component is usable out of the box, and its modular design facilitates a great deal of customization. For instance, here is a screen shot from the RichJTable project:

RichJTable

You can find many other JTable extensions:

That’s just a quick search…there are many more out there.

Strong Specific, Weak General

All of these customizations — spreadsheets, tree tables, etc — extend JTable. The variety of custom components demonstrate just how flexible the original JTable design is. Is this a problem?

From page 164 of The Invisible Future: The Seamless Integration Of Technology Into Everyday Life:

In design, there is a trade-off between weak general and strong specific systems. Tools, like people, seem to be either a jack-of-all-trades, or specialized. Inherently “super-appliances” fall into the jack-of-all-trades weak-general category.

This weak general vs. strong specific trade-off plays a role in the design of all tools, including chisels, screwdrivers, bicycles and supercomputers. For reasons that we shall see, strong general systems have never been an option. One has always had to make a choice.

You can read Bill Buxton’s complete essay here. The point is, a Swiss Army Knife has a lot of tools, but they are all relatively weak. A dedicated spoon works a lot better than the weak spoon found on a Swiss Army Knife.

Lack of Outside Innovation

JTable is really good, but at its heart it is a weak-general tool. Writing a general-purpose table component is really hard, and the Swing team did a damn fine job with JTable. Thus, everybody else down the food chain (that I’m aware of) simply extends JTable.

JTable is good enough for 95% (?) of the use cases out there, but it is not as good as a dedicated spreadsheet. This is the problem. Grid components in dedicated spreadsheet applications are designed with one purpose in life: to display and edit spreadsheets. As such, they are strong-specific GUI components. In a dedicated spreadsheet, the GUI is crisp and responsive, focus traversal works, mouse clicks work, and data commits at the right time.

Many people have tried — including myself — to extend and coerce JTable into a spreadsheet component. But Swing JTable is subject to engineering tradeoffs like every other piece of software, and it can only be pushed so far. You can make JTable look and behave a lot like a good spreadsheet, but I doubt we will ever achieve perfection.

Consider IntelliJ IDEA, a product renowned for keyboard navigation. Unfortunately, keyboard navigation sucks whenever they use an editable JTable, such as in the Change Signature dialog:

IDEA Table

Perhaps I need to embed a little video here to demonstrate the problems…basically, keyboard and mouse navigation just feel incredibly broken and wrong. JTable does the best that it can, but it is not a dedicated data entry component. JTable’s primary function is tabular data display, tabular data entry is a secondary feature for this general purpose GUI component.

A Radical Idea

I submit to you this idea:

Someone should write a dedicated Swing data entry grid component from the ground up, without extending JTable.

Random thoughts…

  • This is a really hard project.
  • This is a strong-specific component, designed for one purpose: data entry in a grid, like a spreadsheet.
  • There are no constraints. You don’t have to support existing renderers, editors, or anything else.
  • You should be able to achieve 100% fidelity with a dedicated spreadsheet component.
  • Many businesses would *love* a data entry grid that *really works* flawlessly.

Anybody writing a data entry grid from scratch would certainly be accused of NIH. I can hear it now…”You are writing what??? You should just extend JTable! 95% of the functionality is already there!”

I believe that starting with a general-purpose component might make that final 5% impossible.

Conclusion

I hope I make it clear that this article is not a criticism of JTable at all. Pretending that a single GUI component can be perfect at *every* task is foolish and naive. Yet…I cannot say I have ever heard of someone writing a Java data entry grid — of Excel caliber — from scratch. Every single grid component I have seen extends JTable.

For most purposes, extending JTable is the right choice. But surely there are cases where a strong-specific, dedicated data entry grid component is more appropriate.


8 Responses to “JTable: Time to Rethink NIH?”

Jesse Says:

I spent a few days planning this exact project back when I was still working on Swing. I didn’t get much further than setting up a java.net project and writing down some ideas:
https://jwtable.dev.java.net/jwtable.pdf

Dennis S Says:

I took a look @Jesse’s pdf and it has some really good ideas. I’d love a discussion with the author of Visi-Calc, or other such “*.calc’s” to see what they thought they’d done right and wrong in their designs. Some of them are open source now. Good points, as always. Maybe Scala or Ruby will make this trivial, maybe not.

As Always…

Trey Moore Says:

I believe you are absolutely correct here. Never have I seen a Swing-based component that can truly hang w/ Excel, and it would be beneficial for a huge number of people to have a responsive, Excel-like data grid. What is OpenOffice using? Is it swing-based?
Its not like enough people haven’t tried to solve this problem using JTable, and yet all of their attempts have come up short. You are right. The time has come to solve this problem with a brand new component targeted specifically at Excel-like behavior.

-Trey

Neil Weber Says:

I don’t think the problem is NIH. The problem is as you mentioned in your first random thought: “This is a really hard project.” It’s far easier to hack JTable.

WinForms has two table controls: a ListView ala Windows Explorer and a DataGrid. I think this is right. People use table components for a wide variety of purposes and I don’t think one component can suit all needs.

Mike Says:

You should check out the JGrid component of Jeppers: http://jeppers.sf.net/

JEff Says:

I am currently working on a project that a user can read, modify, and write excel via POI. We use a JTable and I think it works well if you pretty good at customizing a JTable.

Guruprasad Says:

I am having three independent Jtables (No corelation between the tables), after clicking the Find mode in one table, all the tables are enabling the Find Mode. But What I need is only the table I am clicking on, the find mode should be enabled to read the query and other tables should still show the data.

Thanks,
Guru

Ziad Mansouri Says:

Done! And I’d be surprised if it hasn’t been done a number of times already and won’t be done some more times too! I can’t say for whom, and I can’t share the code, but I can say that Swing, to its credit, gives you all you need to accomplish a very close Excel-ish look and feel. The take-away for me is that one can write a quality component from scratch (or based on JTable :)) if one puts their mind to it.

Leave a Reply