Reputation: 453
I would like to know how to increase the Font size of the title column in JTable Swing?
I'm usning Netbeans.
Best regards.
Daniel
Upvotes: 2
Views: 11124
Reputation: 324108
To keep the same Font family and just change the size you can use:
JTableHeader header = table.getTableHeader();
header.setFont( header.getFont().deriveFont(16) );
Upvotes: 6
Reputation: 109815
not sure from your question, then I post both options
1) set Font for JTable myTable.setFont(new Font("Arial", Font.PLAIN, 10))
2) set Font for TableHeader
final TableCellRenderer tcrOs = table.getTableHeader().getDefaultRenderer();
table.getTableHeader().setDefaultRenderer(new TableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel lbl = (JLabel) tcrOs.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
lbl.setBorder(BorderFactory.createCompoundBorder(lbl.getBorder(), BorderFactory.createEmptyBorder(0, 5, 0, 0)));
lbl.setHorizontalAlignment(SwingConstants.LEFT);
if (isSelected) {
lbl.setForeground(Color.red);
lbl.setFont(new Font("Arial", Font.BOLD, 12));
} else {
lbl.setForeground(Color.darkGray);
lbl.setFont(new Font("Arial", Font.PLAIN, 10));
}
return lbl;
}
});
Upvotes: 1
Reputation: 30865
You just need to call the getTableHeader()
method. Then on the object of class JTableHeader
use the setFont(/*font*/)
method to set new font.
table.getTableHeader().setFont( new Font( "Arial" , Font.BOLD, 15 ));
Upvotes: 6