왜 다음 코드가 java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
이됩니까?JTable ArrayIndexOutOfBoundsException
JTable oTable = new JTable();
for (int row = 0; row < table.getRowCount(); row++) {
for (int column = 0; column < table.getColumnCount(); column++) {
oTable.setValueAt(table.getValueAt(row, column), row, column);
}
}
표가 정렬 키를 사용하여 정렬되었습니다. SortKeys가 작동하면 GUI의 뷰가 업데이트되지만 기본 데이터 (모델)는 변경되지 않습니다. 기본 모델을 변경하거나 뷰의 데이터로 새 테이블을 작성해야합니다.
DefaultTableModel model = (DefaultTableModel) table.getModel();
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
table.setRowSorter(sorter);
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
sortKeys.add(new RowSorter.SortKey(model.findColumn("col title"), SortOrder.DESCENDING));
sortKeys.add(new RowSorter.SortKey(model.findColumn("col title 2"), SortOrder.DESCENDING));
sortKeys.add(new RowSorter.SortKey(model.findColumn("another col title"), SortOrder.DESCENDING));
sorter.setSortKeys(sortKeys); //this should trigger a .sort()
모델이 업데이트되지 않는 이유는 모르지만 그렇지 않습니다.
매우 혼란 질문을 당신은 두 개의 독립적 인 JTable의 변수,'oTable'와'table'을 가지고있는 것 같습니다 있기 때문이다. oTable 변수 만 사용해야합니다. –
1) EDT에서 GUI 관련 문제를 수행합니다. 2) 더 빨리 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –
을 입력하고 예외 – andersoj