Terai Atsuhiro 2022-08-07 (日) 00:18:06

http://terai.s55.xrea.com/swing/headerfont/screenshot.png

JTableHeader hd = jtable.getTableHeader();
hd.setReorderingAllowed(false);
hd.setDefaultRenderer(new HeaderRenderer(hd.getDefaultRenderer()));

class HeaderRenderer implements TableCellRenderer {
  private final TableCellRenderer tcr;
  private final Font font = new Font("Sans-serif", Font.PLAIN, 32);
  private final Font orgfont;
  public HeaderRenderer(TableCellRenderer tcr) {
    this.tcr = tcr;
    this.orgfont = UIManager.getFont("TableHeader.font");
  }
  public Component getTableCellRendererComponent(JTable tbl, Object val,
                          boolean isS, boolean hasF, int row, int col) {
    JLabel lbl = (JLabel)tcr.getTableCellRendererComponent(
                                          tbl, val, isS, hasF, row, col);
    if(col==0) lbl.setFont(font);
    else lbl.setFont(orgfont);
    return lbl;
  }
}
UIManager.put("TableHeader.font", new FontUIResource(font));