JTable data only shown after scrolling
Posted
by
Christian 'fuzi' Orgler
on Stack Overflow
See other posts from Stack Overflow
or by Christian 'fuzi' Orgler
Published on 2012-10-28T16:08:10Z
Indexed on
2012/10/28
17:00 UTC
Read the original article
Hit count: 246
I wrote a method, that creates my DefaultTableModel and there I'm going to add my records. When I set the model to my JTable, the data rows are blank. After scrolling the data gets displayed correct.
How can I avoid this and display the data from the first moment?
EDIT: I imported the javax.swing.table.DefaultTableModel --> is this correct?
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);
}
© Stack Overflow or respective owner