how can I create a DefaultTable from my ArrayList:
public class FileModel extends AbstractTableModel implements TableModel{
List<Object[]> data = new ArrayList<>();
String titles[] = new String[] { "File Name", "Pages", "Media Box Height", "Media Box Width", "Trim Box Height",
"Trim Box Width", "Path", "Error" };
Class<?> types[] = new Class[] { String.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, String.class, String.class };
I want to use it for a color renderer, because at the moment the renderer just colors "Strings"... The DefaultModel should look like:
DefaultTableModel model = new DefaultTableModel(data, columnNames) {
public Class getColumnClass(int column) {
return getValueAt(0, column).getClass();
}
};
My current Colorrenderer looks so:
public class ColorRenderer extends DefaultTableCellRenderer {
static final long serialVersionUID = 1L;
final int STATUS_COL = 7;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int col) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
String type = (String) table.getModel().getValueAt(row, 7);
if ("Error" == type) {
component.setBackground(Color.RED);
component.setForeground(Color.WHITE);
} else if (isSelected) {
component.setBackground(table.getSelectionBackground());
component.setForeground(table.getSelectionForeground());
} else {
component.setBackground(table.getBackground());
component.setForeground(table.getForeground());
}
return component;
}
}