我有一个内部JPanel
组件JTable
。当我运行下面编写的代码时,表格会正确呈现和更新。一旦我尝试使用该scrollPane
方法,表格根本不会呈现。谁能向我解释这是为什么?
private static class GameHistoryPanel extends JPanel {
private DataModel model;
private JTable table;
private int currentRow;
private int currentColumn;
private final Dimension HISTORY_PANEL_DIMENSION = new Dimension(190,460);
public GameHistoryPanel() {
this.setLayout(new BorderLayout());
this.model = new DataModel();
this.table = new JTable(model);
this.add(table.getTableHeader(), BorderLayout.NORTH);
this.add(table, BorderLayout.CENTER);
// JScrollPane scrollPane = new JScrollPane();
// scrollPane.setViewportView(table);
// this.add(scrollPane);
setPreferredSize(HISTORY_PANEL_DIMENSION);
this.currentRow = 0;
this.currentColumn = 0;
}
public void increment(Board board, Move move) {
model.setValueAt(move, currentRow, currentColumn);
if(board.currentPlayer().getAlliance() == Alliance.WHITE) {
currentColumn++;
} else if (board.currentPlayer().getAlliance() == Alliance.BLACK) {
currentRow++;
currentColumn = 0;
}
validate();
repaint();
}
}