faraj
asked on
Hidding collumn in JTable
I want to hide a specific collumn in a JTable how to do this ?
you can probably set column with to 0.
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.removeCol umn(TableC olumn) 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","r ow0col2"},
{"row1col0","row1col1","ro w1col2"}};
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];
}
- You can remove the TableColumn from the TableColumnModel. See JTable.getColumnModel() and TableColumnModel.removeCol
- 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","r
{"row1col0","row1col1","ro
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.
public void getColumnCount() {
return (blockColumn1) ? data[0].length-1 : data[0].length;
}
whatever.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>no you got a small collum with a ...
try to set both minwidth and maxwidth to 0, as well as column in table header.
try to set both minwidth and maxwidth to 0, as well as column in table header.
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 .