- All Known Implementing Classes:
- DefaultTableColumnModel
- See Also:
- Top Examples, Source Code
void addColumn(TableColumn aColumn)
- See Also:
removeColumn(javax.swing.table.TableColumn)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void addColumnModelListener(TableColumnModelListener x)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
TableColumn getColumn(int columnIndex)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int getColumnCount()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[86]Resize each column according to the maximum data width of the column
By Anonymous on 2002/10/14 19:15:16 Rate
//Resize each column according to the maximum data width of the column
public static void calcColumnWidths ( JTable table ) {
int padding = 5; // Cell Padding
JTableHeader header = table.getTableHeader ( ) ;
TableCellRenderer defaultHeaderRenderer = null;
if ( header != null )
defaultHeaderRenderer = header.getDefaultRenderer ( ) ;
TableColumnModel columns = table.getColumnModel ( ) ;
TableModel data = table.getModel ( ) ;
int margin = columns.getColumnMargin ( ) ; // only JDK1.3
int rowCount = data.getRowCount ( ) ;
int totalWidth = 0;
int viewPortTotalWidth = 0;
for ( int i = columns.getColumnCount ( ) - 1; i > = 0; --i ) {
TableColumn column = columns.getColumn ( i ) ;
int columnIndex = column.getModelIndex ( ) ;
int width = -1;
TableCellRenderer h = column.getHeaderRenderer ( ) ;
if ( h == null )
h = defaultHeaderRenderer;
if ( h != null ) { // Not explicitly impossible
Component c = h.getTableCellRendererComponent ( table, column.getHeaderValue ( ) , false, false, -1, i ) ;
width = c.getPreferredSize ( ) .width;
}
for ( int row = rowCount - 1; row > = 0; --row ) {
TableCellRenderer r = table.getCellRenderer ( row, i ) ;
Component c = r.getTableCellRendererComponent ( table, data.getValueAt ( row, columnIndex ) , false, false, row, i ) ;
width = Math.max ( width, c.getPreferredSize ( ) .width ) ;
}
if ( width > = 0 )
column.setPreferredWidth ( width + margin + padding ) ; // < 1.3: without margin
else
; // ???
if ( i < 6 ) {
viewPortTotalWidth += column.getPreferredWidth ( ) ;
}
totalWidth += column.getPreferredWidth ( ) ; //
}
}
int getColumnIndex(Object columnIdentifier)
- See Also:
getColumn(int)
, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int getColumnIndexAtX(int xPosition)
- See Also:
JTable.columnAtPoint(java.awt.Point)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int getColumnMargin()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
Enumeration<TableColumn> getColumns()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
boolean getColumnSelectionAllowed()
- See Also:
setColumnSelectionAllowed(boolean)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int getSelectedColumnCount()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int[] getSelectedColumns()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
ListSelectionModel getSelectionModel()
- See Also:
setSelectionModel(javax.swing.ListSelectionModel)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int getTotalColumnWidth()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void moveColumn(int columnIndex,
int newIndex)
- See Also:
- IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void removeColumn(TableColumn column)
- See Also:
addColumn(javax.swing.table.TableColumn)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void removeColumnModelListener(TableColumnModelListener x)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setColumnMargin(int newMargin)
- See Also:
getColumnMargin()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setColumnSelectionAllowed(boolean flag)
- See Also:
getColumnSelectionAllowed()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setSelectionModel(ListSelectionModel newModel)
- See Also:
getSelectionModel()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples