• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

making a JTable column not visible

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the one. Thanks a million.

Cheers, Jared.
reply
    Bookmark Topic Watch Topic
  • New Topic