Java Code
import java.awt.*;
import javax.swing.*;
public class JTableDataColor extends JApplet
{
String[ ] colHeadings = { "Name", "Sport", "Location", "Age" };
Object data[ ][ ] = { { "Liz", "Skiing", "Fort Fun", "21" },
{ "C. M.", "Cooking", "Denver", "56" },
{ "Oscar", "Mtn Biking","Mars", "19" },
};
JScrollPane scrollPane;
JTable table;
public void init( )
{
table = new JTable( data, colHeadings );
// change the color of the column headings
table.getTableHeader().setBackground(Color.RED);
table.getTableHeader().setForeground(Color.YELLOW);
// change colors of the selected row
table.setSelectionBackground( Color.ORANGE );
table.setSelectionForeground( Color.WHITE );
// change color of the grid lines
table.setGridColor( Color.GREEN );
// specify which grid lines to display
table.setShowHorizontalLines( true ); // this is the default
table.setShowVerticalLines( false );
// change the color of the data cells
table.setBackground( Color.BLUE );
table.setForeground( Color.CYAN );
table.setPreferredScrollableViewportSize(new Dimension(400, 70));
//Create the scroll pane and add the table to it.
scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane);
}
}
©2006 by E.S.Boese. All Rights Reserved