This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

making a JTable column not visible

 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to keep some data in a column of a JTable, but I don't want that column to be visible to the user. For example, a database ID column should be populated for each row, but not made visible to the user.

I can't seem to find a table.getColumn("id").setVisible(false) kind of solution. Any ideas?

Cheers, Jared.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want the column itself visible, something like this might work



if you don't want the column visible, something like this
table.removeColumn(table.getColumnModel().getColumn(0));

where 0 is the column number.
This removes it from the display area of the table, but not the model.
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
if you don't want the column visible, something like this
table.removeColumn(table.getColumnModel().getColumn(0));

where 0 is the column number.
This removes it from the display area of the table, but not the model.[/QB]


Thanks, I have been trying this but it seems to be removing the column from the underlying model too. If I do:

table.removeColumn(table.getColumnModel().getColumn(6));

The column does not appear in the JTable anymore, however if I then try:

Object o = table.getValueAt(row, 6); // row changes depending the selection

I get an index out of range exception:

java.lang.ArrayIndexOutOfBoundsException: 6 >= 6

I know I've done this before, but something has gone astray ...

Cheers, Jared.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change
Object o = table.getValueAt(row, 6);

to
Object o = dtm.getValueAt(row, 6);
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the one. Thanks a million.

Cheers, Jared.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic