Using JXTreeTable to display grouped data

Let me start by ranting about Swing. Its a lame duck. It could never really take off. But we can’t live with it, can’t live without it. Especially if the application is a legacy Swing application written 10 years ago.

So, when I had the prospect of displaying simple grouped data, the fear of writing my custom JTree absolutely seized me. That is when i thought about the SwingX project. In its present form, it buggy, unusable, messed up etc. It took me close to an hour to figure out a stable release from the quagmire of broken links that Google came up with. At last, the Maven Central came to my rescue in the form of the following 3 magical lines:

The First 90%

After being associated with Swing for a good part of my life, I have come to believe that 90% of your job is done if you can create a good Model, especially for unwieldy components like JTable and JTree. So, I do the same for this as well. In this case, I represent grouped data with a Map<String, List<BankDetail>>. All I want is to display the groups as nodes and the Lists under these nodes. This is how I model it:

The remaining 10%

The tying up the model to the JXTreeTable is the simplest thing on the earth:

This is how it looks like:

UsingJXTreeTable_1UsingJXTreeTable_2

 

The source code can be found here:

https://github.com/paawak/blog/tree/master/code/lambda-demo

The main class to run is: GroupingDemoFrame.

I found the following post very useful in my efforts:

http://javanbswing.blogspot.com/2013/08/swing-treetable-example-using.html

Leave a Reply

Your email address will not be published. Required fields are marked *