• 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

Hiding columns in JTable

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you hide more than one column and make it/them return when you want???
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TableColumn column1 = null;
column1 = JTable1.getColumnModel().getColumn(no. of the col you want to hide);
column1.setMaxWidth(0);
column1.setMinWidth(0);
column1.setWidth(0);
column1.setPreferredWidth(0);
Hi keiyia .. You could try this code to hide the column you want.
To unhide them, you could try the same code & set the max, min, width & preferredwidths to the required dimension in the condition you want the columns to show.
for eg;
TableColumn column1 = null;
column1 = JTable1.getColumnModel().getColumn(no. of the col you want to hide);
column1.setMaxWidth(100);
column1.setMinWidth(10);
column1.setWidth(100);
column1.setPreferredWidth(100);
Thanks
Meghna
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have the capability of hiding them, but just can't get them back.
ok, here's the situation:
i have a split pane witha table on one side. on the menubar is a view option. it has 4 checkbox menuitems. i need for the the appearance to change everytime an item is selested or deselected. if selected, it needs to be hidden (which i already had). if deselcted, return as to original state (which i can't get to worked).
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try out !!!
To hide a Column<Column No>

To enable the Column (i.e width =100)<Column No>

write the code in selection of the menu.
Onselection use enable code.
Deselection use hide code.
This code works for me.

 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Whether width = 0 or required size

 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Whether width = 0 or required size
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is another way of doing it. Sets the 1st column to invisible.
DefaultTableColumnModel columnModel = new DefaultTableColumnModel() {
public void addColumn(TableColumn tc) {
boolean first = true;
if (first) {
first = false;
return;
}
super.addColumn(tc);
}
};
table.setColumnModel(columnModel);
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic