我有一张表,当用户提示我这样做时,我想填充该表。问题是,我无法预测表格最终会有多少行。在构造我的面板,该表将显示我有向JScrollPane动态添加JTable
// add empty scrollPane to JPanel which will later hold table
scrollPane = new JScrollPane();
add(scrollPane);
这个类包含了时,我想终于显示表
public void displayTable(String[] columnNames, String[][] dataValues)
{
table = new JTable(dataValues, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(300, 80));
table.setFillsViewportHeight(true);
scrollPane.add(table);
this.setVisible(true);
scrollPane.repaint();
}
问题是,会被调用,表方法从不显示。我只看到ScrollPane没有内部表格的轮廓。为什么表格不显示,我该如何解决?
为了更快提供更好的帮助,请包括[SSCCE](http://sscce.org)。 – mre 2013-02-15 17:26:20
我认为这很简短并且重要。我的问题不清楚吗? – Matt 2013-02-15 17:29:36
Swing有很多细微之处。你给我们的信息越多,我们就越容易帮助你。否则,我们都在黑暗中开枪,尽管有时候我们很幸运。 – mre 2013-02-15 17:30:54