0
JTable의 마지막 행에 이상한 문제가 있습니다. 선을 선택할 수 없으며 열만 선택할 수 있습니다. 내가 할 때 칼럼의 데이터가 보이지 않습니다. 모든 행이 흰색이되었습니다. 오류가 표시되지 않아 오류의 위치를 파악할 수 없습니다. 나는 JTable가이JTable에서 행 데이터를 선택할 때 행 데이터가 표시되지 않습니다.
table = new JTable(new StudentTableModel());
//create button to sort the table data
table.setAutoCreateRowSorter(true);
//use the costum rendrer for the table data
table.setDefaultRenderer(String.class, new StudentTableRenderer());
table.setDefaultRenderer(float.class, new StudentTableRenderer());
table.setDefaultEditor(float.class, new AverageCellEditor());
여기가 내 문제를 알아 낸 JTable로 모델
public class StudentTableModel extends DefaultTableModel implements TableModel {
public StudentTableModel(Model model, Teacher teacher, Classe classe, Lesson lesson) {
super();
if (model != null) {
this.model = model;
this.teacher = teacher;
this.classe = classe;
students = model.getStudentsInClass(classe.toString());
this.lesson = lesson;
Collections.sort(students, new PersonComparator());
fireTableDataChanged();
}
}
public int getColumnCount() {
if (model == null)
return 0;
return names.length;
}
public String getColumnName(int col) {
return names[col];
}
public int getRowCount() {
if (model == null)
return 0;
return students.size();
}
public Object getValueAt(int line, int col) {
switch (col) {
case 0:
return students.get(line).getLastName();
case 1:
return students.get(line).getFirstName();
case 2:
float note;
if (lesson == null)
note = students.get(line).getAverage().getMark();
else
note = students.get(line).getAverages().get(lesson).getMark();
if (note == -1)
return null;
else
return note;
case 3:
if (lesson == null)
return students.get(line).getAverage().getComment();
else
students.get(line).getAverages().get(lesson).getComment();
}
return null;
}
public boolean isCellEditable(int row, int col) {
if (col < 2)
return false;
if (lesson != null && teacher.getLesson().equals(lesson)) {
return true;
}
if (lesson == null && classe.getResponsable().equals(teacher) && col == 3) {
return true;
}
return false;
}
public void removeTableModelListener(TableModelListener arg0) {
}
public void setValueAt(Object object, int line, int col) {
switch (col) {
case 2:
if (lesson == null)
students.get(line).getAverage().setMark((float) object);
else
students.get(line).setAverage(lesson,(float) object);
break;
case 3:
if (lesson == null)
students.get(line).getAverage().setComment((String) object);
else
students.get(line).getAverages().get(lesson)
.setComment((String) object);
break;
}
model.updatesTeachersAndStudents();
}
}