Мы пытаемся реализовать модель таблицы, которая расширяет абстрактную модель таблицы. Мы внедрили флажок в абстрактной модели таблицы. До сих пор мы не можем изменить значение флажка. Пожалуйста, дайте нам несколько предложений.Установка флажка в абстрактной модели таблицы
Вот код FileTableModel:
import javax.swing.table.AbstractTableModel;
import java.text.SimpleDateFormat;
public class FileTableModel extends AbstractTableModel {
private FileList sourceList;
private FileList targetList;
private ActionList actionList;
private final String[] COLUMN_NAME = {"Name(Source)", "Size(B)", "Last modified", "Action",
"Name(Target)", "Size(B)", "Last modified"};
private Class[] columnClasses = new Class[]{
String.class, Long.class, SimpleDateFormat.class, String.class,
String.class, Long.class, SimpleDateFormat.class,
};
public FileTableModel(FileList sourceList, FileList targetList, ActionList actionList) {
this.sourceList = sourceList;
this.targetList = targetList;
this.actionList = actionList;
}
public int getColumnCount() {
return 7;
} // A constant for this model
public int getRowCount() {
return targetList.size();
} // # of files in dir
public String getColumnName(int col) {
return COLUMN_NAME[col];
}
public Class getColumnClass(int col) {
return columnClasses[col];
}
public Object getValueAt(int row, int col) {
switch (col) {
case 0:
if (sourceList.get(row) != null) return sourceList.get(row).getName();
else return "";
case 1:
if (sourceList.get(row) != null) {
if (!sourceList.get(row).isDirectory())
return new Long((sourceList.get(row).length()));
else return "<Folder>";
} else return "";
case 2:
SimpleDateFormat sourceDate = new SimpleDateFormat("HH:mm:ss");
if (sourceList.get(row) != null)
return sourceDate.format(sourceList.get(row).lastModified());
else return "";
case 3:
if (actionList.get(row) != null)
return actionList.get(row);
else return "";
case 4:
if (targetList.get(row) != null) return targetList.get(row).getName();
else return "";
case 5:
if (targetList.get(row) != null) {
if (!targetList.get(row).isDirectory())
return new Long((targetList.get(row).length()));
else return "<Folder>";
} else return "";
case 6:
SimpleDateFormat targetDate = new SimpleDateFormat("HH:mm:ss");
if (targetList.get(row) != null)
return targetDate.format(targetList.get(row).lastModified());
else return "";
default:
return null;
}
}
}
Задавая вопрос о проблеме, вызванной вашим кодом, вы получите гораздо лучше ответы, если вы предоставляете код, который люди могут использовать для воспроизведения проблемы (см. http://stackoverflow.com/help/mcve для получения дополнительной информации). Можете ли вы, по крайней мере, добавить свой вопрос к своим классам «FileList» и «ActionList»? –