为什么我在application中创建的JTable有列名,但是在Applet中创建就是没有列名,只有内容???
代码如下:
String[] columnNames = {"First Name",
                "Last Name",
                "Sport",
                "# of Years",
                "Vegetarian"}; Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};

JTable table = new JTable(data, columnNames);

解决方案 »

  1.   

    需要把这个JTable加到一个滚动面板JScrollPane上,这样就ok了
      

  2.   

    这个我在GUI里碰到过,是显示问题,应该先让jtable显示,setVisible(true)PC火烈鸟
    http://blog.csdn.net/pcfirebird/
      

  3.   

    l楼说得对,增加一个滚动面板材可以,
    JScrollPane scroll = new JScrollPane(jtable);
    scroll.setBounds(new Rectangle(12, 60, 830, 400));
    this.getContentPane().add(scroll, null);
    这样应该可以