这是我的第一篇文章,所以任何有关如何让我的帖子更好的建议都会很棒!
借助本网站的研究,我能够生成一个表格,我可以更改字体,更改对齐方式,并保持当前的外观。但是,我不能改变颜色,不确定该怎么做。任何建议将不胜感激!
创建JTable后,我打电话给:
table.getTableHeader()。setDefaultRenderer(new HeaderRenderer(table));
private class HeaderRenderer implements TableCellRenderer {
DefaultTableCellRenderer renderer;
public HeaderRenderer(JTable table) {
setOpaque(true);//this is an attempt to change color
renderer = (DefaultTableCellRenderer)
table.getTableHeader().getDefaultRenderer();
renderer.setHorizontalAlignment(JLabel.CENTER);
}
@Override
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int col) {
Component cell = renderer.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, col);
setBackground(headerColor);//this is an attempt to change color
//cell.setBackground(headerColor);//this is an attempt to change color
cell.setFont(headerFont);//this successfully changes font
return cell;
}
}
有人能指出我的方向或帮我创建一个能够着色,居中并具有“Nimbus”外观的桌面标题吗?