1

I have a JTable and am passing a data array into the TableModel. I wish to retain all columns in the data model as I need them all for background data processing, but I wish to show only some of the columns in the JTable.

How do I achieve this -- to remove a data column from the view (the visualized JTable) but not from the model (the TableModel)?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Umesh K
  • 13,436
  • 25
  • 87
  • 129
  • How to remove a column has been answered, however a better solution would be to create your own table model which provides the table with the relevant data. – vickirk Jul 28 '11 at 07:45
  • You can hide columns dynamically, as shown [here](http://stackoverflow.com/questions/6793257/add-column-to-exiting-tablemodel/6796673#6796673) and [here](http://stackoverflow.com/questions/6793257/add-column-to-exiting-tablemodel/6798013#6798013). – trashgod Jul 28 '11 at 08:09

2 Answers2

3

JTable has

public void removeColumn(TableColumn aColumn)
StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • I know remove column method. My doubt is how will it arrange data in columns. Say I have 3 columns. I have model data of 3 columns. I want to show only 2 columns. So how will it recognize which data to put in which column? – Umesh K Jul 28 '11 at 07:47
  • Methods of JTable to convert view column index to model and opposite public int convertColumnIndexToModel(int viewColumnIndex) and public int convertColumnIndexToView(int modelColumnIndex) – StanislavL Jul 28 '11 at 07:55
1

Override getColumnCount of the model to return less columns that there is. Then put your hidden columns as last columns of the model.

Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68