I have an interesting case where there are three JTables that must be synced together in a rather peculiar fashion.
The first column of all tables must resize together (have this working), and all other columns must resize together.
Here is an image of the tables:
table_sample.jpg
I would like to resize all of the "Date" columns together so that the width of these are always consistent. Looking for suggestions.
Here's pseudo code for what I want to happen:
if (user resizes first column)
resize first column of other two tables
else if (user resizes another column)
perform for each table 1, 2, and 3
loop through all columns 2 through <MAX NUMBER COLUMNS>
if (column != column being resized by user)
resize column width to match user's resized column
Here's what I've tried:
Extended the TableColumnModelListener and implemented above in columnMarginChanged().
Problem: Resizing of columns in code triggers events all tables, which in turn triggers events in all tables, etc, etc...
Attempted Fix: Remove listeners for tables while columnMarginChanged()'s
code is being executed, put listeners back afterwards.
*** This does NOT seem to solve the problem. The other events are still being triggered.
Attempted Fix: Implement custom TableColumnMode by extending DefaultTableColumnModel
and overriding fireColumnMarginChanged() to add disabling logic.
*** Did not work. Broke default functionality of the DefaultTableColumnModel.
Tables would not automatically repaint when structure changed or data was updated.
If someone could give me a simple working example, OR just tell me an alternative approach to try, I'd be very grateful.
Regards,
-Will