API Changes to the JTable and its associated classes ==================================================== Policy #1: Formally separate the JTable and DefaulTableModel Policy #2: Delete identifier methods when they are covers for integer ones Policy #3: Make all methods with row and column arguments consistent (row first) Policy #4: In renderers/editors: replace (TableColumn, row) with (row, column) Policy #5: Remove sorting from DefaultTableModel - sort by delegation Policy #6: Make the JTable configurable for default renderers/editors Policy #7: Add cell selection as well as row/column selection Policy #8: Handle all update/insert/delete events together - like JList Policy #9: Remove selection management from JTable, forward to the ListSelectionModel Policy #10: Replace all addColumn(...) methods in JTable with one: addColumn(TableColumn), provide a full set of constructors in TableColumn Policy #11: Store model index in the TableModel to avoid id lookup JTable ------ DELETE (#1) public TableColumn addColumn(Object columnIdentifier, Vector columnData) public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, Vector columnData) public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor) public void removeColumn(Object columnIdentifier) public void addRow(Object[] rowData) public void addRow(Vector rowData) public void removeRow(int rowIndex) public void moveRow(int startIndex, int endIndex, int toIndex) public void insertRow(int rowIndex, Object[] rowData) public void insertRow(int rowIndex, Vector rowData) public void setNumRows(int newSize) public void setDataVector(Vector newData, Vector columnIds) public void setDataVector(Object[][] newData, Object[] columnIds) protected void checkDefaultTableModel() DELETE (#2) public Object getValueAt(Object columnIdentifier, int rowIndex) public boolean isCellEditable(Object columnIdentifier, int rowIndex) public void setValueAt(Object aValue, Object columnIdentifier, int rowIndex) public boolean editColumnRow(Object identifier, int row) public void moveColumn(Object columnIdentifier, Object targetColumnIdentifier) public boolean isColumnSelected(Object identifier) CHANGE (#3) FROM: public Object getValueAt(int columnIndex, int rowIndex) public void setValueAt(Object aValue, int columnIndex, int rowIndex) public boolean isCellEditable(int columnIndex, int rowIndex) public boolean editColumnRow(int columnIndex, int rowIndex) public boolean editColumnRow(int columnIndex, int rowIndex, EventObject e) public Rectangle getCellRect(int column, int row, boolean includeSpacing) TO: public Object getValueAt(int row, int column) public void setValueAt(Object aValue, int row, int column) public boolean isCellEditable(int row, int column) public boolean editCellAt(int row, int column) public boolean editCellAt(int row, int column, EventObject e) public Rectangle getCellRect(int row, int column, boolean includeSpacing) DELETE (#10) public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor) public TableColumn addColumn(Object columnIdentifier, int width) CHANGE (#4) FROM: public Component prepareEditor(TableCellEditor editor, TableColumn aColumn, int row) TO: public Component prepareEditor(TableCellEditor editor, int row, int column) ADD (Some other methods in the TableModel interface) public String getColumnName(int column) public Class getColumnClass(int column) ADD (#6) protected Hashtable defaultRenderersByColumnClass; protected Hashtable defaultEditorsByColumnClass; public void setDefaultRenderer(Class columnClass, TableCellRenderer renderer) public TableCellRenderer getDefaultRenderer(Class columnClass) public void setDefaultEditor(Class columnClass, TableCellEditor editor) public TableCellEditor getDefaultEditor(Class columnClass) protected void createDefaultEditors() protected void createDefaultRenders() DELETE (#8) public void tableRowsInserted(TableModelEvent e) public void tableRowsRemoved(TableModelEvent e) CHANGE (typo) FROM: public void getPreferredScrollableViewportSize(Dimension size) TO: public void setPreferredScrollableViewportSize(Dimension size) ADD (#7) public isCellSelected(int row, int column) CHANGE (#7) FROM: protected boolean simultaneousRowColumnSelectionAllowed; public void setSimultaneousRowColumnSelectionAllowed(boolean flag) public boolean getSimultaneousRowColumnSelectionAllowed() TO: protected boolean cellSelectionEnabled; public void setCellSelectionEnabled(boolean flag) public boolean getCellSelectionEnabled() DELETE (#9) protected boolean multipleSelectionAllowed; public void setMultipleSelectionAllowed(boolean flag) public boolean getMultipleSelectionAllowed() protected boolean emptySelectionAllowed; public void setEmptySelectionAllowed(boolean flag) public boolean getEmptySelectionAllowed() ADD (#9) public void setSelectionMode(int selectionMode) DELETE (New JScrollPane validation policy) public void setBounds(int x,int y,int w,int h) protected void resizeAndRepaint(int x, int y, int w, int h) TableColumn ----------- ADD (#2, #11) public void setModelIndex(int anIndex) public int getModelIndex() CHANGE (#2, #11) FROM: public TableColumn(Object anIdentifier) TO: public TableColumn(int modelIndex) DELETE (#6) protected TableCellRenderer createDefaultCellRenderer() protected TableCellEditor createDefaultCellEditor() ADD (#10) public TableColumn(int modelIndex, int width) public TableColumn(int modelIndex, int width, TableCellRenderer cellRenderer, TableCellEditor cellEditor) TableColumnModel ---------------- DELETE (#2) public TableColumn getColumn(Object identifier) public boolean isColumnSelected(Object identifier) ADD (#9) public void setSelectionModel(ListSelectionModel newModel) public ListSelectionModel getSelectionModel() DELETE (#9) public void setMultipleSelectionAllowed(boolean flag) public boolean getMultipleSelectionAllowed() public void setEmptySelectionAllowed(boolean flag) public boolean getEmptySelectionAllowed() public void makeSelectionEmpty() public void selectAll() public void clearSelection() public void setColumnSelectionInterval(int index0, int index1) public void addColumnSelectionInterval(int index0, int index1) public void removeColumnSelectionInterval(int index0, int index1) public boolean isColumnSelected(int column) public int getSelectedColumn() DefaultTableColumnModel ----------------------- DELETE (#2) public TableColumn getColumn(Object identifier) public boolean isColumnSelected(Object identifier) DELETE (#9) protected boolean multipleSelectionAllowed; protected boolean emptySelectionAllowed; public void setMultipleSelectionAllowed(boolean flag) public boolean getMultipleSelectionAllowed() public boolean getEmptySelectionAllowed() public void setEmptySelectionAllowed(boolean flag) public void makeSelectionEmpty() public void selectAll() public void clearSelection() public void setColumnSelectionInterval(int index0, int index1) public void addColumnSelectionInterval(int index0, int index1) public void removeColumnSelectionInterval(int index0, int index1) public boolean isColumnSelected(int column) public int getSelectedColumn() TableModelEvent --------------- CHANGE (#2) FROM: public TableModelEvent(TableModel source, Object columnIdentifier) public TableModelEvent(TableModel source, Object columnIdentifier, int rowIndex) public TableModelEvent(TableModel source, Object columnIdentifier, int rowtartIndex, int endIndex) public TableModelEvent(TableModel source, int startIndex, int endIndex) public int getStartIndex() public int getEndIndex() public Object getColumnIdentifier() TO: public TableModelEvent(TableModel source) public TableModelEvent(TableModel source, int row) public TableModelEvent(TableModel source, int firstRow, int lastRow) public TableModelEvent(TableModel source, int firstRow, int lastRow, int column) public int getFirstRow() public int getLastRow() public int getColumn() ADD (#8) public static final int INSERT = 1; public static final int UPDATE = 0; public static final int DELETE = -1; public static final int HEADER_ROW = -1; public static final int ALL_COLUMNS = -1; protected int type; public TableModelEvent(TableModel source, int firstRow, int lastRow, int column, int type) TableModelListener ------------------ DELETE (#8) public void tableRowsInserted(TableModelEvent e) public void tableRowsRemoved(TableModelEvent e) BasicTableUI ------------ CHANGE (#4) FROM: protected Component prepareRenderer(TableCellRenderer renderer, JTable table, TableColumn aColumn, int row) TO: protected Component prepareRenderer(TableCellRenderer renderer, JTable table, int row, int column) CHANGE (#7) FROM: transient protected int firstIndex; TO: transient protected int anchorRowIndex; ADD transient protected int anchorColumnIndex; BasicTableHeaderUI ------------------ DELETE (#2) public Rectangle getHeaderRect(Object columnIdentifier) TableCellRenderer and DefaultCellRenderer ----------------------------------------- CHANGE (#4) FROM: Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, Object columnID, int rowIndex) TO: Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, int row, int column) TableCellEditor and DefaultCellEditor ------------------------------------- CHANGE (#4) FROM: Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, Object columnID, int rowIndex) TO: Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) TableModel ---------- DELETE (#2, #11) public Object getColumnIdentifier(int columnIndex) public int getColumnIndex(Object columnIdentifier) AbstractTableModel ------------------ DELETE (#2) public Object getColumnIdentifier(int columnIndex) public int getColumnIndex(Object columnIdentifier) ADD (A convenience for locating columns by name - not used in JTable) public int findColumn(String columnName) CHANGE (implementation) - returns letters as default names public String getColumnName(int columnIndex) DELETE (#8) protected void fireTableRowsInserted(TableModelEvent e) protected void fireTableRowsRemoved(TableModelEvent e) ADD (conveniences for constructing/dispatching TableModelEvents) protected void fireTableDataChanged() protected void fireTableStructureChanged() protected void fireTableRowsInserted(int firstRow, int lastRow) protected void fireTableRowsUpdated(int firstRow, int lastRow) protected void fireTableRowsDeleted(int firstRow, int lastRow) protected void fireTableCellUpdated(int row, int column) DefaultTableModel ----------------- DELETE (#2) public int getColumnIndex(Object columnIdentifier) public Object getColumnIdentifier(int index) public void changeColumnIdentifier(Object oldIdentifier, Object newIdentifier) public void removeColumn(Object columnIdentifier) public void changeColumnIdentifier(int columnIndex, Object newIdentifier) protected static Vector generateIds(int numColumns) DELETE (#5) public boolean sort() public void setSortColumn(int columnIndex) public void setSortColumn(Object columnIdentifier) public int getSortColumn() public void setSortAscending(boolean ascending) public boolean getSortAscending() public void setSortAutomatically(boolean autoSort) public boolean getSortAutomatically() protected void quicksort(int left, int right) protected int doCompare(int column, Vector v1, Vector v2) protected void swap(int i, int j) protected boolean checkAutoResort()