trouble in hiding colum of jtable

i want to hide Jtable's column and its data but the point is data should remains in table model

or we can say we acces that data any where from this method.

table.getModel().getValueAt(...)

below is the code which i used to hide column from table.

table coulmn tb= priceTable.getColumn(priceTable.getColumnName(2));

TableColumnModel tcm= priceTable.getColumnModel();

tcm.removeColumn(tb);

but the problem is that this column data still show in table.column already hide.

what i do for it?

[545 byte] By [sachin_javadev1a] at [2007-11-27 3:41:02]
# 1

>i want to hide Jtable's column and its data

What you wanted to do is a lot trickier than you think..... don't remove the column, instead, set the width of the column to zero. This technique will effectively remove the column from display, but what you need to do is figure out how to navigate around the hidden column (and how to unhide the column, i.e., reset the column width to its original setting).

good luck!

V.V.

viravana at 2007-7-12 8:44:31 > top of Java-index,Desktop,Core GUI APIs...
# 2
but how i set its width so that it not visible to userhow can i set column width?
sachin_javadev1a at 2007-7-12 8:44:31 > top of Java-index,Desktop,Core GUI APIs...
# 3

this is an excerpt from a program I wrote years ago:

public void setColWidth(int beg, int end, int width) {

int i,newWidth;

TableColumnModel TCM=getColumnModel();

if (width<0) {// size to fit

Rectangle rect;

TableCellRenderer renderer;

Component c;

Dimension size;

for (int col=beg;col<end;col++) {// hide columns

if (col>=getColumnCount()) continue;

newWidth=0;

for (int row=0;row<=maxRowUsed;row++) {

rect=getCellRect(row,col,false);

renderer=getCellRenderer(row,col);

c=renderer.getTableCellRendererComponent(this,getValueAt(row,col),true,true,row,col);

c.setBounds(rect);

size=c.getPreferredSize();

if (size.width>newWidth) newWidth=size.width;

}

if (newWidth>0) TCM.getColumn(col).setPreferredWidth(newWidth);

}

} else {// unhide columns

for (i=beg;i<end;i++) {

if (i>=getColumnCount()) return;

TCM.getColumn(i).setMinWidth(0);

TCM.getColumn(i).setPreferredWidth(width);

}

}

}

See if you can make use of it somehow.

V.V.

viravana at 2007-7-12 8:44:31 > top of Java-index,Desktop,Core GUI APIs...
# 4

Don't set the width the column to zero.

Your approach is correct. All you need to do is remove the TableColumn from the TableColumnModel. Can't tell from your code why its not working. Here is a working example:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=743041&start=7

camickra at 2007-7-12 8:44:31 > top of Java-index,Desktop,Core GUI APIs...