我有一個JPanel
組件,其內部爲JTable
。當我按照下面的代碼運行代碼時,表格會正確呈現和更新。只要我嘗試使用scrollPane
方法,表格根本就不渲染。任何人都可以向我解釋爲什麼這是?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();
}
}
我認爲通過回答(@trashgod),你的問題和代碼的一切重要的基礎在那裏, – mKorbel