开发者

How to increase the Font of the title column in JTable Swing?

I would like to know how to increase the Font开发者_StackOverflow中文版 size of the title column in JTable Swing?

I'm usning Netbeans.

Best regards.

Daniel


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 ));


To keep the same Font family and just change the size you can use:

JTableHeader header = table.getTableHeader();
header.setFont( header.getFont().deriveFont(16) );


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;
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜