我写了一个方法,它创建了我的 DefaultTableModel,我将在那里添加我的记录。当我将模型设置为我的 JTable 时,数据行是空白的。滚动后数据显示正确。
我怎样才能避免这种情况并从一开始就显示数据?
编辑:我导入了 javax.swing.table.DefaultTableModel --> 这是正确的吗?
private DefaultTableModel _dtm;
private void loadTable(Vector<Member> members) {
loadTableModel();
try {
lbl_state.setText("Please wait");
for (Member actMember : members) {
String gender = "";
if (actMember.getGender() == MemberView.MEMBER_MALE) {
gender = "männlich";
} else {
gender = "weiblich";
}
_dtm.addRow(new Object[]{
actMember.getNname(),
actMember.getVname(),
actMember.getCity(),
actMember.getStreet(),
actMember.getPlz(),
actMember.getMail(),
actMember.getPhonenumber(),
actMember.getBirthdayString(),
actMember.getStartDateString(),
gender,
actMember.getBankname(),
actMember.getAccountnumber(),
actMember.getBanknumber(),
actMember.getGroup().toString(),
(actMember.hasAccess() ? "JA" : "NEIN"),
actMember.getWriteDateString(),
(actMember.hasDrinkAbo() ? "JA" : "NEIN")
});
}
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
tbl_results.setModel(_dtm);
}
private void loadTableModel() {
_dtm = new DefaultTableModel(new Object[]{"Nachname",
"Vorname",
"Ort",
"Straße",
"PLZ",
"E-Mail",
"Telefon",
"Geburtsdatum",
"Beitrittsdatum",
"Geschlecht",
"Bankname",
"Kontonummer",
"Bankleitzahl",
"Gruppe",
"hat Zugriff",
"Einschreibdatum",
"Getränkeabo"}, 0);
tbl_results.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
}