• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hide jtable column problem  RSS feed

 
David Pantale
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

I'm trying to hide a jtable column with the following line:

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

and I'm bombing on an ArrayIndexOutOfBoundsException.

There must be a simple way to avoid this. Any suggestions?

Thanks
Dave
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works OK for me
 
David Pantale
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that the table does not yet have data in it and that is causing the out of bounds exception. I guess my questions are, does the removeColumn only work when there is data in the table? Is there a way to set the table before it has data to not show a column?

Dave
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BeForthrightWhenCrossPostingToOtherSites
http://forums.oracle.com/forums/thread.jspa?threadID=1556564
 
David Pantale
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Danny (sorry about the cross post, I'll do better in the future) but I saw that thread and, to be honest, Swing newbie that I am, I didn't fully understand it.
Specifically, I didn't quite get the answer -

TableModel model = table.getModel();
Object value = model.getValueAt(table.convertRowToModel(row), 3);

I really don't know what that bit of code is accomplishing. In fact it looks like they have it wrong. I think they meant table.convertColumnIndexToModel.

Dave


 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does the removeColumn only work when there is data in the table?


It only works when you have TableColumns in the TableColumnModel.

The table columns are usually created when you add a TableModel to the table.

You can easily create a TableModel without any data (just column headings). Read the DefaultTableModel API for the appropriate constructor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!