![](/img/trans.png)
[英]How do I color individual cells of a JTable based on the value in the cell?
[英]How do I change JTable title cell color in Netbeans
我试图更改NetBeans中JTable标题单元格的颜色,但没有改变。 但是尝试在文本编辑器中做同样的事情,它运行完美。
这是与我的问题有关的Java代码:
jTable1.getTableHeader().setBackground(Color.GREEN);
请帮我。
如果您使用的是netbeans
则main()
方法中会有一行。 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
注释此行,然后查看结果。
问题是Netbeans提供了设置外观。 您可以像这样创建自定义渲染器
public NewJFrame() {
initComponents();
jTable1.getTableHeader().setDefaultRenderer(new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
l.setBorder(new LineBorder(Color.black, 1));
l.setBackground(Color.GREEN);
return l;
}
});
}
也使用GUI Builder制作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.