package com.tweeteye.gui.model;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import com.tweeteye.entity.ImageRecord;
import com.tweeteye.entity.enumiration.SearchTypeEnum;
import com.tweeteye.gui.MainWindow;
import javax.swing.ImageIcon;
public class ImageTableModel extends AbstractTableModel
{
private static final long serialVersionUID = 1669175969068584634L;
protected SearchTypeEnum type;
public List<ImageRecord> dataList = new ArrayList<ImageRecord>();
@SuppressWarnings("rawtypes")
private Class[] columnTypes = { java.lang.Boolean.class,javax.swing.ImageIcon.class,
javax.swing.ImageIcon.class, java.lang.Object.class };
private String[] columnNames = {"Select","Logo","Image","Title"};
public List<ImageRecord> getData() {
return dataList;
}
public void setData(List<ImageRecord> dataList) {
this.dataList = dataList;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Class getColumnClass(int column) {
return columnTypes[column];
}
public String getColumnName(int col) {
return columnNames[col].toString();
}
public void setValueAt(Object arg0, int arg1, int arg2) {
ImageRecord imageRecord=dataList.get(arg1);
if (arg2 == 0) {
imageRecord.setSelected((Boolean) arg0);
}
fireTableCellUpdated(arg1, arg2);
}
public Object getValueAt(int arg0, int arg1) {
if (arg1 == 0)
return dataList.get(arg0).getSelected();
if (arg1 == 1)
return dataList.get(arg0).getImage();
else
return dataList.get(arg0).getTitle();
}
@Override
public boolean isCellEditable(int row, int column) {
if (column == 0)
return true;
else
return false;
}
public int getColumnCount() {
return columnTypes.length;
}
public int getRowCount() {
return dataList.size();
}
public SearchTypeEnum getType() {
return type;
}
public void setType(SearchTypeEnum type) {
this.type = type;
}
}
现在我只想在“已选择”列中选择一个复选框。我正在从 eBay 获取产品信息并将其显示在表格中,我的第一列包含复选框,但我想要单选按钮。如何做到这一点。