Link to home
Start Free TrialLog in
Avatar of glogin
glogin

asked on

JTable column problem

My program use JTable to show information in form of table.

Is it possible to disable column swapping feature such that user can only resize the column size, but he/she cannot swapping the columns (eg. swapping column one to column four by drag-and-drop). How to achieve it ?

Thanks.........
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For restricting column movement use
    table.getTableHeader().setReorderingAllowed(false);

For restricting column resizing use
    table.getTableHeader().setResizingAllowed(false);

For individual column resizing use
    table.getColumnModel().getColumn(index).setResizable(false/true);

    NOTE:This does not work (due to a feature) prior to the Java 2 Platform, Standard Editiion, version 1.3 (Kestrel).

JTableHeader.setReorderingAllowed(boolean reorderingAllowed)

          Sets whether the user can drag column headers to reorder columns.