Ok, I have this code here, which is my replacement for the standard standard Swing TableModel. Which I consider an absolute nightmare, my question is that I have a lot of rowIndex and columIndex options, is there a way I can share the description between them for a more standardized and less working finger? Thanks!
package atablemodel; import java.util.ArrayList; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; @SuppressWarnings("serial") public class ATableModel extends AbstractTableModel { private ArrayList<String> cn = new ArrayList<String>(); private ArrayList<ArrayList<RowDataObject>> rd = new ArrayList<ArrayList<RowDataObject>>(); public ATableModel(String[] columnames, Object[][] rowdata) { for (int i = 0; i < columnames.length; i++) { cn.add(columnames[i]); } for (int i = 0; i < rowdata.length; i++) { ArrayList<RowDataObject> rdot1 = new ArrayList<RowDataObject>(); for (int i2 = 0; i2 < rowdata[i].length; i2++) { rdot1.add(new RowDataObject(rowdata[i][i2])); } rd.add(rdot1); } } public String getColumnName(int column) { return cn.get(column); } public boolean isCellEditable(int rowIndex, int columnIndex) { return getCellEditable(rowIndex, columnIndex); } public void setValueAt(Object aValue, int rowIndex, int columnIndex) { boolean editable = getRDO(rowIndex, columnIndex).getEditable(); getRDO(rowIndex, columnIndex).setEditable(true); getRDO(rowIndex, columnIndex).setData(aValue); getRDO(rowIndex, columnIndex).setEditable(editable); } public int getColumnCount() { return cn.size(); } public int getRowCount() { return rd.size(); } public Object getValueAt(int rowIndex, int columnIndex) { return getRDO(rowIndex, columnIndex).getData(); } public TableModel returnTableModel() { return this; } public boolean getCellEditable(int rowIndex, int columnIndex) { return getRDO(rowIndex, columnIndex).getEditable(); } public void setCellEditable(int rowIndex, int columnIndex, boolean editable) { getRDO(rowIndex, columnIndex).setEditable(editable); } public void setAllCellsEditable(boolean editable) { int x, y; for (x = 0; x < rd.size(); x++) { for (y = 0; y < rd.get(x).size(); y++) { getRDO(x, y).setEditable(editable); } } } public void setRowEditable(int rowIndex, boolean editable) { for (RowDataObject rdo : getRDORow(rowIndex)) { rdo.setEditable(editable); } } public void setColumnEditable(int columnIndex, boolean editable) { for (RowDataObject rdo : getRDOCol(columnIndex)) { rdo.setEditable(editable); } } public RowDataObject getRDO(int rowIndex, int columnIndex) { return rd.get(rowIndex).get(columnIndex); } public ArrayList<RowDataObject> getRDORow(int rowIndex) {
source share