table不显示
我的Table类 extends的是JScrollPane
public class MyTable extends JScrollPane
{
public JTable table = null;
public MyTable ()
{
super();
tableModel = new TableModel ();
table = new JTable (tableModel);
this.add(table);
this.setViewportView ( table );
this.getViewport().setView(table);
this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
}
}
public static void main(String[] args)
{
static JFrame frame = new JFrame("Table Display");
MyTable mt = new MyTable ();
frame.getContentPane().add(mt ,BorderLayout.CENTER);
frame.setVisible(true);
}
1:运行的结构式可以看到2个JScrollBar 但就是没有Table 怎么回事
2:我把main函数改成如下 Table可以成功显示
public static void main(String[] args)
{
static JFrame frame = new JFrame("Table Display");
MyTable mt = new MyTable ();
static JScrollPane scrollPane = new JScrollPane(mt.table)
frame.getContentPane().add(scrollPane ,BorderLayout.CENTER);
frame.setVisible(true);
}
百思不得其解 哪位大侠能够指点指点