• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hide a column in JTable view?

 
Robert Benson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My understanding of "removeColumn" from the table view is flawed. I thought that the column is removed from only the view and that the data column is still in the model.
In practice, this is not the case for me, so my understanding is incorrect. The column appears to be deleted from the view and the model. I was hoping to use column 0 (room number) as a hidden column.
However removeColumn throws everything out of alignment:

I have verified this by using log.info to display all the table columns. column 0 has gone and all other columns shift left by 1 column.



However, the following works for me as a hidden column:



Is my understanding wrong? I searched the coderanch for a similar posting there is a thread in the Swing forum that I could have replied on http://www.coderanch.com/t/345725/GUI/java/hide-column-JTable-view but as I'm doing the SCJD I thought I'd post in this forum.



Regards, Robert.

P.S. Thanks Roel for all your previous answers.
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like the api doc states removeColumn removes the column from the view. When you try to access it from the view (e.g. JTable itself) it's not present anymore. In the model it's still present. Example:

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not show the recNo in the JTable, but I didn't use the removeColumn method or set*Width methods. Just don't include the column in your table model.

So if you have a model MyModel with properties a, b, c, d and you only want to show b and in your JTable you would get something like this (significant code only, just as a quick example, no good coding practices applied ):



Robert Benson wrote:P.S. Thanks Roel for all your previous answers.

No problem at all
 
Robert Benson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops

I mixed up my view and model names. While I thought I was looking at the model, I was in fact looking at the view. It works now.

Thanks, Robert.
 
bernard adaba
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was hiding the recNo in the view, but with the discussion from other Ranchers, i realised it was irrelevant.
Warmest regards.
Bernard
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic