【发布时间】:2012-01-04 15:35:41
【问题描述】:
我正在尝试调整位于选项卡视图中的滚动面板中的两个 JTable 的大小。我已经设法将框架的大小设置为 12000、5000,但是 Jtable/scrollPanel 没有打球。
我找到了一些代码来设置表格的列大小,但它没有填充 Jframe,它只是在表格/scrollPanel 的底部添加了一个滚动条
任何人都可以想出一种方法来让表格填满框架并且仍然可以滚动吗?
表格文件是:
public class ViewInTablePET extends JPanel {
private String[][] rowData = new String[0][];
private String columnNames[] = {"Shop", "Type", "price", "dateAcquired", "notes"};
private DefaultTableModel tableMod = new DefaultTableModel(rowData, columnNames);
private JTable table = new JTable(tableMod);
public ViewInTablePET() {
String bob;
String[] dan;
for (Integer i = 0; i < AppModel.getArrayListPet().size(); i++) {
bob = AppModel.getArrayListPet().get(i).toString();
dan = AppModel.getStringAsArray(bob, "\t");
tableMod.insertRow(i, new Object[]{dan[0], dan[1], dan[2], dan[3], dan[4]});
}
JScrollPane scrollPane = new JScrollPane(table);
this.add(scrollPane, BorderLayout.CENTER);
}
}
Fram 文件是:
public class ViewInTabbs extends JFrame {
JLabel Average = new JLabel("Click a table row to get the average price");
public ViewInTabbs() {
JTabbedPane tabs = new JTabbedPane();
ViewInTablePetShope petShop = new ViewInTablePetShope();
ViewInTablePET pet = new ViewInTablePET();
tabs.add("Pet Shope", (JPanel) petShop);
tabs.add("Pets in the shop", (JPanel) pet);
this.setTitle("Tabb View of Data");
this.add(tabs, BorderLayout.CENTER);
this.setSize(12000, 5000);
this.setVisible(true);
this.add(Average, BorderLayout.SOUTH);
}
public void setAverage(String ave) {
this.Average.setText(ave);
}
}
【问题讨论】: