我的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);
}
百思不得其解 哪位大侠能够指点指点
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);
}
百思不得其解 哪位大侠能够指点指点
。要不是
this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
你连滚动条都看不到。
没有贴出来
我贴出2次的效果
但是 我的table的数据我在tablemode中已经填写好了
前面一个构造函数里
不是加在滚动面版里面
所以就不行了
jp.add(table);加上这个
写好的一个JTable可以直接放JScrollPanel上面添加就好了。。
主要是我在tablemodel中 用了filestuctureChange了
而我又重写了tablechange这个函数 在这个函数中并只有一句 table.revalidate
所以table并没有repaint
导致没有显示 这个问题已经解决 不需要重写tablechange函数即可感谢各位 散分罗!