Click to See Complete Forum and Search --> : JTable Header only shows when there are elements in table


Frank Falcone
August 4th, 1999, 08:21 PM
I am using a JTable inside a JScrollPane and want the Headers to
appear all the time. Currently, They only appear if there are
elements inside the stringtablemodel. Also, I would like to manually
set the widths of each column. I see how to disable the automatic
setting of the width, but not how to specify the width.

How can this be done? Is there any sample code showing this?

Frank.

unicman
August 5th, 1999, 08:48 AM
I don't think that its true (atleast in JDK1.1.5).
I had created JTable and TableModel in JDK1.1.5. There I didn't have this problem. I'm not sure about JDK1.2 as I haven't tried it there.

Here is my table model...


TableModel dataModel = new AbstractTableModel()
{
public int getColumnCount()
{
return names.length;
}

public int getRowCount()
{
return vCurrExp.size();
}

public Object getValueAt(int row, int col)
{
Vector expVect = new Vector();
((Experience)vCurrExp.elementAt( row )).getAll( expVect );
return (expVect.elementAt( col ));
}

public String getColumnName(int column)
{
return names[column];
}

public Class getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}

public boolean isCellEditable(int row, int col)
{
return false;
}

public void setValueAt(Object aValue, int row, int column)
{
return; // Function not perfected becase we won't edit any values from Table.
// If u r going to edit values, u will have to handle this function.
}
};





- UnicMan
http://members.tripod.com/unicman