Skip to main content

Add columns dynamically to JXTreeTable

4 replies [Last post]
Joined: 2006-11-14


I'm relatively new to SwingX and may be my problems are related to that.

Anyway, I've got a JXTreeTable which is populated with some standard informations. Now I want to add one timestamp column for each timestamp in a database table and display the entries according to their timestamps.
The problem is since the treeTable shall be aware of changes in the database (which can happen any time) showing and hiding columns will not work . So I will have to add and remove columns dynamically when an entry is added to or removed from the database.

The treeTable is intended to look like this:

Interval--Min--Max--[timestamp]... (and here may be multiple timestamp columns)
Interval1---0-----5------(entry for this timestamp)
Interval2---6-----10----(entry for this timestamp)

I implemented a TreeTableModel that recieves the database changes and updates both the nodes in the model and the columns in the treeTable. And it seems to work as far as the model is concerned.
But the column changes don't have any effect on the table which you can see in the window, no matter how many times I invoke the reload() method on the model or repaint() on the table itself. The rows on the other hand are updated and displayed correctly, .

Now the questions:
Is it possible to change the table structure (i.e. add/remove columns) of a JXTreeTable dynamically?
And if so, how do I do that?

I'd be very grateful for any suggestions.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-12-04


it was an error on our side - we fired the events whenever the model changed, but forgot to register the treetable as listener for those events - sorry.

Everything is working as supposed now.

Regards, Aloys

Joined: 2006-10-23


I think its possible to dynamically alter a JXTreeTable. I'm fairly sure I managed to get it to work.

The one thing which might help, at least if you're removing columns is to also call

this.columnRemoved(new TableColumnModelEvent(this.getColumnModel(), 0, this.getRowCount()));

where 'this' is the name of the instance of your treeTable (I remove the columns in a method contained within my implementation of treeTable so I use this to indicate the particular instance of it.)

Um there appears to be a similar method for columnAdded, although according to the API, the columnAdded method will not be used explicitly by application code. So I'm not 100% sure on that one.

Somebody else will probbably be able to give you a better answer, but I thought I'd share what I've found out as a starting point at least

Joined: 2006-11-14

Hi and thanks for your reply.

I tried it but it didn't work.
And I still don't understand why.


Joined: 2003-06-11


from your description I don't quite understand what you want to achieve and what you are doing so far, there are so many screws to turn when tree/tables are concerned :-) Can you show a small (!) runnable example to demonstrate what you are expecting vs. what's not working?