Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

visible unvisible jtable column  RSS feed

 
kizgincocuk kizgincocuk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..
I am in trouble with jtable columns..
My table read data from a text file and i want to select which of the table's column will be visible.I have button like table header and in case of double click i wanna make that column invisible.But the problem is i do not want to lose table data(can't use removecolumn).I tried to set columnwidth(0) but in that case three dots make me sick.
I really appreciate any suggestions..
thanks all.
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say extend the JTable's data model (default is javax.swing.table.TableModel) and have it keep track of which columns are visible and not. Add a couple methods to hide and reveal columns. The getColumnCount() method should return the number of visible columns and the getValueAt() method should skip columns in the underlying data that have been set invisible by the user.
 
kizgincocuk kizgincocuk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx joe ..
but in that case I will lose table data..I can't reach unvisible columns data.
I have to rehandle all data for some sort and delete action.
am I wrong ?
thanks in advance..
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The data remains unchanged in the Vector (or object arrays) you read it into.
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use removeColumn() on JTable to hide a column - it just removes the column from the View - Table, doesnot delete the data in the Model - TableModel.
Use addColumn() on JTable to show that column.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!