/** * This method indicates whether changes to the model should cause the width to be dynamically * recalculated. * * @param isDynamicAdjustment Boolean value to determine if the width should be dynamically * calculated */ public void setDynamicAdjustment(boolean isDynamicAdjustment) { // May need to add or remove the TableModelListener when changed if (this.isDynamicAdjustment != isDynamicAdjustment) { if (isDynamicAdjustment) { table.addPropertyChangeListener(this); table.getModel().addTableModelListener(this); } else { table.removePropertyChangeListener(this); table.getModel().removeTableModelListener(this); } } this.isDynamicAdjustment = isDynamicAdjustment; }
public RowNumberTable(JTable table) { main = table; main.addPropertyChangeListener(this); main.getModel().addTableModelListener(this); setFocusable(false); setAutoCreateColumnsFromModel(false); setSelectionModel(main.getSelectionModel()); TableColumn column = new TableColumn(); column.setHeaderValue(" "); addColumn(column); column.setCellRenderer(new RowNumberRenderer()); getColumnModel().getColumn(0).setPreferredWidth(50); setPreferredScrollableViewportSize(getPreferredSize()); }