[英]change the style(font, font size, background color) of column name in Jtable, Jframe
i want to ask how to change the style(font, background color) of column name in table.我想问一下如何更改表格中列名的样式(字体、背景颜色)。 i'm using Jtable, Jframe, Java
我正在使用 Jtable、Jframe、Java
table_test.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"NO", "CODE", "ADDRESS", "CLASS"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
table_test.setRowHeight(30);
table_test.setSelectionMode(0);
jScrollPane1.setViewportView(table_test);
table_test.getColumnModel().getColumn(0).setMinWidth(55);
table_test.getColumnModel().getColumn(0).setMaxWidth(55);
table_test.getColumnModel().getColumn(1).setMinWidth(120);
table_test.getColumnModel().getColumn(1).setMaxWidth(120);
table_test.getColumnModel().getColumn(2).setMinWidth(280);
table_test.getColumnModel().getColumn(2).setMaxWidth(280);
table_test.getColumnModel().getColumn(3).setMinWidth(63);
table_test.getColumnModel().getColumn(3).setMaxWidth(63);
This is the image :这是图像:
You can set it like using table header set font,您可以像使用表格标题设置字体一样设置它,
table.getTableHeader().setFont( ... );
Example:例子:
table.getTableHeader().setFont(new Font("Times New Roman", Font.BOLD, 12));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.