Change the JTable header colorTag(s): Swing
About cookies on this site
We use cookies to collect and analyze information on site performance and usage,
to provide social media features and to enhance and customize content and advertisements.
Got it
import java.awt.*;
import javax.swing.*;
import javax.swing.table.JTableHeader;
public class SimpleJTable extends JFrame {
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
SimpleJTable() {
setTitle( "Simple Table Application" );
setSize( 300, 200 );
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
Object[][] cellData = {
{"row1-col1", "row1-col2"},
{"row2-col1", "row2-col2"},
{"row3-col1", "row3-col2"},
{"row4-col1", "row4-col2"},
{"row5-col1", "row5-col2"}};
String[] columnNames = {"col1", "col2"};
table = new JTable(cellData, columnNames);
scrollPane = new JScrollPane( table );
topPanel.add( scrollPane, BorderLayout.CENTER );
JTableHeader anHeader = table.getTableHeader();
anHeader.setForeground(new Color(0).yellow);
anHeader.setBackground(new Color(0).black);
}
public static void main(String ... arg) {
SimpleJTable mainFrame = new SimpleJTable();
mainFrame.setVisible( true );
}
}
comment Comments ( )