• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable does not display header

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic