如何使文本在jtable粗体,我尝试了以下,它确实工作的颜色,但使文本粗体我走错了地方
class ColourRender extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable tblData,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Component cellComponent = super.getTableCellRendererComponent(
tblData, value, isSelected, hasFocus, row, column);
if (tblData.getValueAt(row, 3).equals("M")) {
cellComponent.setForeground(forMen);
} else {
cellComponent.setForeground(forWomen);
}
return cellComponent;
}
class boldRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable tblData,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
Component cellComponent = super.getTableCellRendererComponent(
tblData, value, isSelected, hasFocus, row, column);
if (tblData.getValueAt(row, 1).equals(bib)) {
cellComponent.setFont(cellComponent.getFont().deriveFont(
Font.BOLD));
} else {
cellComponent.setFont(cellComponent.getFont().deriveFont(
Font.PLAIN));
}
return cellComponent;
}
}
}
这是和table一起上的课
tblData.getColumn("Bib no").setCellRenderer(new CustomRenderer());
tblData.getColumn("M/F").setCellRenderer(new CustomRenderer());
1条答案
按热度按时间sg24os4d1#
你创建了一个粗体字体,但什么也不做:你从不调用它
setFont(...)
任何地方。即。,
对于颜色,在else块中将前景颜色设置为null,以使颜色更改回默认值。
编辑
例如: