Reputation: 41
I tried to change JTable title cells colour in NetBeans but it doesn't change. But trying to do same things in text editor and it is running perfectly .
This is the Java code related to my problem:
jTable1.getTableHeader().setBackground(Color.GREEN);
Please help me.
Upvotes: 0
Views: 3219
Reputation: 209072
The problem is Netbeans gives a set up look and feel. You can create custom renderer though like this
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;
}
});
}
Also made with GUI Builder
Upvotes: 2
Reputation: 4534
If you are using netbeans
then there will be a line in your main()
method.
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
Comment this line and then see the result.
Upvotes: 2