Board index » jbuilder » make the first column in jdbtable fixed

make the first column in jdbtable fixed


2005-04-25 01:56:26 PM
jbuilder7
dear all:
i need to make the first column in jdbtable fixed, so that column will
always show when the tablescrollpane moved.
does any one know how to do it?
in the case of jtable, i can do it by extends jScrollPane
<code>
public class FixedColumnScrollPane extends JScrollPane {
public FixedColumnScrollPane() {
}
public FixedColumnScrollPane(JTable main, int fixedColumns)
{
super( main );
// Use the table to create a new table sharing
// the DataModel and ListSelectionModel
JTable fixed = new JTable( main.getModel() );
fixed.setSelectionModel( main.getSelectionModel() );
fixed.getTableHeader().setReorderingAllowed( false );
fixed.getTableHeader().setResizingAllowed( false );
fixed.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
main.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
// Remove the fixed columns from the main table
for (int i = 0; i < fixedColumns; i++)
{
TableColumnModel columnModel = main.getColumnModel();
columnModel.removeColumn( columnModel.getColumn( 0 ) );
}
// Remove the non-fixed columns from the fixed table
while (fixed.getColumnCount()>fixedColumns)
{
TableColumnModel columnModel = fixed.getColumnModel();
columnModel.removeColumn( columnModel.getColumn( fixedColumns ) );
}
// Add the fixed table to the scroll pane
fixed.setPreferredScrollableViewportSize(fixed.getPreferredSize());
setRowHeaderView( fixed );
setCorner(TableScrollPane.UPPER_LEFT_CORNER, fixed.getTableHeader());
}
}
</code>
 
 

Re:make the first column in jdbtable fixed

dear all:
i need to make the first column in jdbtable fixed, so that column will
always show when the tablescrollpane moved.
does any one know how to do it?
in the case of jtable, i can do it by extends jScrollPane
<code>
public class FixedColumnScrollPane extends JScrollPane {
public FixedColumnScrollPane() {
}
public FixedColumnScrollPane(JTable main, int fixedColumns)
{
super( main );
// Use the table to create a new table sharing
// the DataModel and ListSelectionModel
JTable fixed = new JTable( main.getModel() );
fixed.setSelectionModel( main.getSelectionModel() );
fixed.getTableHeader().setReorderingAllowed( false );
fixed.getTableHeader().setResizingAllowed( false );
fixed.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
main.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
// Remove the fixed columns from the main table
for (int i = 0; i < fixedColumns; i++)
{
TableColumnModel columnModel = main.getColumnModel();
columnModel.removeColumn( columnModel.getColumn( 0 ) );
}
// Remove the non-fixed columns from the fixed table
while (fixed.getColumnCount()>fixedColumns)
{
TableColumnModel columnModel = fixed.getColumnModel();
columnModel.removeColumn( columnModel.getColumn( fixedColumns ) );
}
// Add the fixed table to the scroll pane
fixed.setPreferredScrollableViewportSize(fixed.getPreferredSize());
setRowHeaderView( fixed );
setCorner(TableScrollPane.UPPER_LEFT_CORNER, fixed.getTableHeader());
}
}
</code>