-1

I have a TableModel to a JTable and I must put it on another table, and I've done it just seting the model of the second table with setModel(firstTableModel).

The problem is that I don't want that one of the columns of the model shows on the second table.

Is it possible to ignore/not display a single column, or I really must create another TableModel with all the redundant information of the first table model to omit just a single column?

halierier
  • 27
  • 5
  • if you are using DefaultTableModel, you are in for a world of hurt. If on the other hand you have your own Model derived from AbstractTableModel, it's pretty easy to share table models, by inheriting a small class the modifies the base with in your case, what columns to show. – MeBigFatGuy Mar 03 '17 at 17:29
  • @Frakcool It's my own model, how can I show the columns that I want? – halierier Mar 03 '17 at 17:32
  • 2
    Post your code. – JB Nizet Mar 03 '17 at 17:59
  • 1
    JTable.removeColumn(TableColumn aColumn), this column isn only removed from JTables view, this Column is still in XxxTableModel and TableColum, this process is reversable in JTables view, more in JTable / TableColumn APIs – mKorbel Mar 03 '17 at 18:10
  • @mKorbel Thank you, it works! – halierier Mar 03 '17 at 18:35
  • @halierier you are welcome – mKorbel Mar 03 '17 at 20:51

1 Answers1

2

Thanks to @mKorbel I found the solution:

secondTable.removeColumn(secondTable.getColumnModel().getColumn(columnIndex));

halierier
  • 27
  • 5