D
Dag Sunde
I have the class below, implementing TableCellRenderer
to use as a custom-renderer for my ColumnHeaders in a JTable.
It works great concerning foreground-color, background-color
and font type/style, but when it comes to the border it
fails me a little bit...:
I would have thought that the line:
setBorder( new LineBorder(Color.decode("#536B7D"),1, false));
would give me a single pixel thick border that matched the thickness
of the cells in the table itself.
But it gives me a fatter (2px) wide border around each column header.
I try to achieve a 'flat' look on the column-headers...
Anyone have a tip to what I do wrong?
//--------------------------
package no.viz.regweb.rk;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import javax.swing.border.*;
public class ColoredHeadRenderer extends JLabel
implements TableCellRenderer {
private Dimension preferredSize;
ColoredHeadRenderer () {
this (new Dimension (80, 17));
}
ColoredHeadRenderer (Dimension preferredSize) {
this.preferredSize = preferredSize;
setOpaque (true);
setBorder( new LineBorder(Color.decode("#536B7D"),1, false));
}
public Dimension getPreferredSize () {
return preferredSize;
}
public Component getTableCellRendererComponent (JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int col) {
if (value instanceof String) {
String s = (String) value;
setFont(new Font("Arial", Font.BOLD, 11));
setForeground(Color.decode("#536B7D"));
setBackground(Color.decode("#c8cfd5"));
// Save the string in preparation to rendering.
setText (s);
}
return this;
}
}
to use as a custom-renderer for my ColumnHeaders in a JTable.
It works great concerning foreground-color, background-color
and font type/style, but when it comes to the border it
fails me a little bit...:
I would have thought that the line:
setBorder( new LineBorder(Color.decode("#536B7D"),1, false));
would give me a single pixel thick border that matched the thickness
of the cells in the table itself.
But it gives me a fatter (2px) wide border around each column header.
I try to achieve a 'flat' look on the column-headers...
Anyone have a tip to what I do wrong?
//--------------------------
package no.viz.regweb.rk;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import javax.swing.border.*;
public class ColoredHeadRenderer extends JLabel
implements TableCellRenderer {
private Dimension preferredSize;
ColoredHeadRenderer () {
this (new Dimension (80, 17));
}
ColoredHeadRenderer (Dimension preferredSize) {
this.preferredSize = preferredSize;
setOpaque (true);
setBorder( new LineBorder(Color.decode("#536B7D"),1, false));
}
public Dimension getPreferredSize () {
return preferredSize;
}
public Component getTableCellRendererComponent (JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int col) {
if (value instanceof String) {
String s = (String) value;
setFont(new Font("Arial", Font.BOLD, 11));
setForeground(Color.decode("#536B7D"));
setBackground(Color.decode("#c8cfd5"));
// Save the string in preparation to rendering.
setText (s);
}
return this;
}
}