Skip to main content

detect ColumnAutoResize in JXTable

2 replies [Last post]
nomike
Offline
Joined: 2006-05-30
Points: 0

I need to detect if a column in a JXTable is autoresized (double-click on divider in column-header, column-control-menu or programmatically)

But I must not detect if a column is resized by dragging the mouse or by programmatically setting a fixed value.

I need this for synchronizing two JTables where one is below the other and both have the same table-model but different data. If the user double-clicks an upper-tables column-header-divisor the two tables-column should be resized to fit the largest value no matter if it's in the top or bottom table...

Is this Possible?

thx in Advance

Nomike aka Michael Postmann

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kleopatra

Hi Michael,

> I need to detect if a column in a JXTable is autoresized (double-click on divider in column-header, column-control-menu or programmatically)
>

all "auto-resize" aka "pack" requests are handled by the columnFactory,
so implementing and setting a custom CF to both tables should be the way
to go. Never tried it and there's nothing in the default implementation
to help you measure the content of two tables - your custom impl
probably will need to be stateful, i.e table-aware. Some raw snippet:

[code]

class MyColumnFactory ... {
JXTable theOtherTable;
public void packColumn(JXTable table,
TableColumnExt columnExt, int margin, int max) {
theOtherTable.getColumnFactory().packColumn(theOtherTable, ...)
// calculate pref width from the parameter table
int myPrefWidth = ...
columnExt.setPrefWidth(Math.max(...));
}

}
[/code]

and some additional caution if you need it work in both directions, that
is if auto-resize may be triggered from any of the tables.

> I need this for synchronizing two JTables where one is below the other and both have the same table-model but different data.

just curious: really the same tableModel? Or the same tableColumnModel
(that's what the code snippet assumes)

Cheers
Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

rbair
Offline
Joined: 2003-07-08
Points: 0

> But I must not detect if a column is resized by
> dragging the mouse or by programmatically setting a
> fixed value.

Just curious, why not?

> Is this Possible?

Not that I am aware of, but I wouldn't imagine it to be too difficult to add it. I'm sure Jeanette would have more insight.

Richard