3

How should I disable just a single column from dragging in JTable? I want to allow other columns from dragging but just the first column (indexed at 0). Thanks.

ashokgelal
  • 80,002
  • 26
  • 71
  • 84
  • Why not having a look at my solution here? [http://stackoverflow.com/a/23829245/458157][1] [1]: http://stackoverflow.com/a/23829245/458157 – gouessej May 23 '14 at 12:30

2 Answers2

5

You should be able to create your own TableColumnModel (extend DefaultTableColumnModel) and to override moveColumn to only call super.moveColumn when the column is allowed to be dragged.

EDIT: Have a look at this post first.

Community
  • 1
  • 1
Peter Lang
  • 54,264
  • 27
  • 148
  • 161
4

Not quite on point for you ....found on another blog

yourJTable.getTableHeader().setReorderingAllowed(false)

this gets the entire table not to reorder columns which is what I needed. Exploring the Override is the correct route

Lucifer
  • 29,392
  • 25
  • 90
  • 143
guest
  • 41
  • 1