我创建了一个新的Jtable,之后我添加了更多行。但是滚动条无法到达最后一行?请帮帮我
这是我的构造函数
public AvailableSeatInRoomFrm() {
setSize(600,400);
setLocation(200,300);
setResizable(true);
setVisible(true);
Object[][] obj1= {{null, null,null} };
String[] col1 ={"ID", "Seat","isPaid"};
DefaultTableModel x = new DefaultTableModel(obj1,col1){
boolean[] canEdit = new boolean [] {
false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
};
tabSeat= new JTable(x);
tabSeat.setPreferredSize(new Dimension(300, 100));
tabSeat.setRowSelectionAllowed(true);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
tabSeat.setPreferredScrollableViewportSize(tabSeat.getPreferredSize());
JScrollPane jc1= new JScrollPane(tabSeat);
jc1.setViewportView(tabSeat);
JPanel pan1 = new JPanel();
pan1.add(jc1);
this.add(pan1);
pack();
}
并且代码添加更多行
public void setListS(Vector<Seat> listS) {
this.listS = listS;
DefaultTableModel m =(DefaultTableModel)tabSeat.getModel();
m.getDataVector().removeAllElements();
TableRowSorter s = new TableRowSorter(m);
tabSeat.setRowSorter(s);
for(Seat t : listS)
{
m.addRow(new Object[]{t.getID(),t.getSeatNumber(),t.getRoom().getID()});
}
}
我创建一个对象AvailableSeatInRoom并调用funcition setLists() 谢谢
答案 0 :(得分:0)
这是我的解决方案
删除tabSeat.setPreferredSize(new Dimension(300, 100));
并更改
tabSeat.setPreferredScrollableViewportSize(tabSeat.getPreferredSize());
到
tabSeat.setPreferredScrollableViewportSize((new Dimension(300, 100))