Код: Выделить всё
JTable table = new JTable(); // actually, a custom JTable type, but it's not the point
// we can't rely on auto-created columns and add them with table.addColumn()
table.addColumn(TableColumns.code());
table.addColumn(TableColumns.name());
Каков правильный способ вставки строк, желательно без дублирования имен столбцов или явной установки количества столбцов модели данных?
Код: Выделить всё
private void fillTable(List doctors) {
DefaultTableModel model = (DefaultTableModel) this.table.getModel();
model.setRowCount(0); // clear rows
// rendering would fail without this ugly line
model.setColumnCount(this.table.getColumnCount());
for (DOCTOR doctor : doctors) {
String code = doctor.getCode();
String text = doctor.getName();
model.addRow(new Object[]{code, text});
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ed-columns
Мобильная версия