This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable does not display header  RSS feed

 
kevin bennett
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having one of those days....
The following code compiles and executes without error, but does not display the header for the table. Can anyone tell me why?

package test;
import javax.swing.*;
public class TableTest extends javax.swing.JFrame {
public TableTest() {
super();
Object[][] testData = {
{"0001", "Kevin"},
{"0002", "Kevin"},
{"0003", "Kevin"},
{"0004", "Kevin"},
{"0005", "Kevin"},
{"0006", "Kevin"},
{"0007", "Kevin"},
{"0008", "Kevin"},
{"0009", "Lili"}
};

String[] colNames = {"CustID", "First Name"};

JTable table = new JTable(testData, colNames);
JScrollPane sp = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new java.awt.Dimension(150, 100));
getContentPane().add(table);

public static void main(String[] args) {
TableTest frame = new TableTest();
frame.pack();
frame.setVisible(true);
}
}
 
kevin bennett
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind....it doesn't help to create the scroll pane if you're just going to add the table directly to the JPanel. Like I said, I'm having one of those days.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!