Link to home
Start Free TrialLog in
Avatar of faraj
faraj

asked on

Hidding collumn in JTable

I want to hide a specific collumn in a JTable how to do this ?
Avatar of kennethxu
kennethxu

you can probably set column with to 0.
Avatar of faraj

ASKER

no you got a small collum with a ...
There are a number of ways to do it. It depends on if you want to do with via the view or model.

- You can remove the TableColumn from the TableColumnModel. See JTable.getColumnModel() and TableColumnModel.removeColumn(TableColumn) in the docs
- You can manipulate the model's getValueAt() and getColumnCount() methods to only display the columns you want. For instance:

//data stored as array in TableModel
String[][] data = {{"row0col0","row0col1","row0col2"},
                   {"row1col0","row1col1","row1col2"}};

boolean blockColumn1 = true;

public void getColumnCount() {
  return (blockColumn1) ? data[0].length-2 : data[0].length-1;
}
public void getRowCount() {
  return data.length;
}
public Object getValueAt(int row,int col) {
  if (blockColumn1) return data[row][col-1];
  else data[row][col];
}
Arrrghhh. Off by one:
public void getColumnCount() {
 return (blockColumn1) ? data[0].length-1 : data[0].length;
}

whatever.
ASKER CERTIFIED SOLUTION
Avatar of Gidi Kern
Gidi Kern
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>no you got a small collum with a ...
try to set both minwidth and maxwidth to 0, as well as column in table header.
Avatar of faraj

ASKER

The problem was that I've setted min and max only for the column and not for the header , thanks a lot it works .