
Signature
And in short, I was afraid.
> > My following codes causes the CPU usage to 100% all the time:
> >
[quoted text clipped - 12 lines]
>
> Christian
Hi Christian,
My CustomTableHeaderRenderer() does the following:
public class CustomTableHeaderRenderer extends JLabel implements
TableCellRenderer {
public Component getTableCellRendererComponent( JTable table,
Object value,
boolean isSelected, boolean hasFocus, int rowIndex, int
vColIndex ) {
// 'value' is column header value of column 'vColIndex'
// rowIndex is always -1
// isSelected is always false
// hasFocus is always false
// Configure the component with the specified value
setText( value.toString() );
// Set tool tip if desired
// setToolTipText( ( String ) value );
JTableHeader header = table.getTableHeader();
// header.setBackground( HEADER_COLOR );
// Disable the column-swapping feature
header.setReorderingAllowed( false );
header.setFont( new Font( "Tahoma", Font.BOLD, 12 ) );
// header.setResizingAllowed( false );
// This somehow removed the border lines
// setBorder( UIManager.getBorder(
"Table.focusCellHighlightBorder" ) );
if ( table.isCellEditable( rowIndex, vColIndex ) ) {
setForeground( UIManager.getColor(
"Table.focusCellForeground" ) );
setBackground( UIManager.getColor(
"Table.focusCellBackground" ) );
}
// this.revalidate();
// Since the renderer is a component, return itself
return this;
}
Yes, my TableModel contains JTable.
Christian Kaufhold - 31 Mar 2004 15:02 GMT
> public class CustomTableHeaderRenderer extends JLabel implements
> TableCellRenderer {
> public Component getTableCellRendererComponent( JTable table,
> Object value,
[quoted text clipped - 17 lines]
> header.setReorderingAllowed( false );
> header.setFont( new Font( "Tahoma", Font.BOLD, 12 ) );
These lines have no business here. Move them to where the table/header
is created. In the renderer code, pick up the settings of the header, or
it won't have any effect:
setFont(header.getFont());
(and also,
setEnabled(header.isEnabled());
setComponentOrientation(header.getComponentOrientation());
)
> if ( table.isCellEditable( rowIndex, vColIndex ) ) {
> setForeground( UIManager.getColor(
> "Table.focusCellForeground" ) );
> setBackground( UIManager.getColor(
> "Table.focusCellBackground" ) );
> }
This is pointless and wrong for a header renderer.
Header cells are never editable.
Christian

Signature
http://www.chka.de/swing/table/faq.html
Michael - 01 Apr 2004 02:28 GMT
>
> > public class CustomTableHeaderRenderer extends JLabel implements
[quoted text clipped - 45 lines]
>
> Christian
Thanks, but how do I disable column swapping?
Christian Kaufhold - 01 Apr 2004 12:11 GMT
> Thanks, but how do I disable column swapping?
JTable t = new JTable(...);
t.getTableHeader().setReorderingAllowed(false);
Christian