Refine search
ColumnFactory factory = new ColumnFactory() { @Override protected void configureTableColumn(TableModel model, TableColumnExt columnExt) { super(...); columnExt.setPrototypeValue(myPrototype[columnExt.getModelIndex()]; } } table.setColumnFactory(factory); table.setModel(myModel);
/** * Creates and configures a TableColumnExt. <code>JXTable</code> calls * this method for each column in the <code>TableModel</code>. * * @param model the TableModel to read configuration properties from * @param modelIndex column index in model coordinates * @return a TableColumnExt to use for the modelIndex * @throws NPE if model == null * @throws IllegalStateException if the modelIndex is invalid * (in coordinate space of the tablemodel) * * @see #createTableColumn(int) * @see #configureTableColumn(TableModel, TableColumnExt) * @see org.jdesktop.swingx.JXTable#createDefaultColumnsFromModel() */ public TableColumnExt createAndConfigureTableColumn(TableModel model, int modelIndex) { TableColumnExt column = createTableColumn(modelIndex); if (column != null) { configureTableColumn(model, column); } return column; }
/** * Initialize the width related properties of the specified column. The * details are specified by the current <code>ColumnFactory</code> if the * column is of type <code>TableColumnExt</code>. Otherwise nothing is * changed. * <p> * * TODO JW - need to cleanup getScrollablePreferred (refactor and inline) * * @param column TableColumn object representing view column * @see org.jdesktop.swingx.table.ColumnFactory#configureColumnWidths */ protected void initializeColumnPreferredWidth(TableColumn column) { if (column instanceof TableColumnExt) { getColumnFactory().configureColumnWidths(this, (TableColumnExt) column); } }
if (!columnExt.isVisible()) throw new IllegalStateException("column must be visible to pack"); int column = table.convertColumnIndexToView(columnExt.getModelIndex()); int width = 0; TableCellRenderer headerRenderer = getHeaderRenderer(table, columnExt); if (headerRenderer != null) { Component comp = headerRenderer.getTableCellRendererComponent(table, columnExt.getHeaderValue(), false, false, 0, column); width = comp.getPreferredSize().width; TableCellRenderer renderer = getCellRenderer(table, columnExt); for (int r = 0; r < getRowCount(table); r++) { Component comp = renderer.getTableCellRendererComponent(table, table .getValueAt(r, column), false, false, r, column); width = Math.max(width, comp.getPreferredSize().width); margin = getDefaultPackMargin();
/** * Creates and adds <code>TableColumn</code>s for each column of the table * model. * <p> * * */ private void createAndAddColumns() { /* * PENDING: go the whole distance and let the factory decide which model * columns to map to view columns? That would introduce an collection * managing operation into the factory, sprawling? Can't (and probably * don't want to) move all collection related operations over - the * ColumnFactory relies on TableColumnExt type columns, while the * JXTable has to cope with all the base types. */ for (int i = 0; i < getModel().getColumnCount(); i++) { // add directly to columnModel - don't go through this.addColumn // to guarantee full control of ColumnFactory // addColumn has the side-effect to set the header! TableColumnExt tableColumn = getColumnFactory() .createAndConfigureTableColumn(getModel(), i); if (tableColumn != null) { getColumnModel().addColumn(tableColumn); } } }
int prefWidth = 75 - table.getColumnMargin(); int prototypeWidth = calcPrototypeWidth(table, columnExt); if (prototypeWidth > 0) { prefWidth = prototypeWidth; int headerWidth = calcHeaderWidth(table, columnExt); prefWidth = Math.max(prefWidth, headerWidth); prefWidth += table.getColumnModel().getColumnMargin(); columnExt.setPreferredWidth(prefWidth);
@Override public void configureTableColumn(final TableModel model, final TableColumnExt columnExt) { super.configureTableColumn(model, columnExt); columnExt.setPrototypeValue(hRefModel.getPrototypeValue(columnExt.getModelIndex())); if (columnExt.getModelIndex() == highestAlertColumnIndex && model.getColumnClass(highestAlertColumnIndex) == AlertRiskTableCellItem.class) { columnExt.setHighlighters(new AlertRiskTableCellItemIconHighlighter(highestAlertColumnIndex));
ColumnFactory factory = new ColumnFactory(){ final JXTable table = new JXTable(); table.setColumnFactory(factory); table.setModel(new DefaultTableModel(20, 5));
/** * Measures and returns the preferred width of the rendering component * configured with the prototype value, if any. Returns -1 if not * applicable. * * @param table the component the renderer lives in * @param columnExt the TableColumn to configure * @return the preferred width of the prototype or -1 if none. */ protected int calcPrototypeWidth(JXTable table, TableColumnExt columnExt) { int prototypeWidth = -1; Object prototypeValue = columnExt.getPrototypeValue(); if (prototypeValue != null) { // calculate how much room the prototypeValue requires TableCellRenderer cellRenderer = getCellRenderer(table, columnExt); Component comp = cellRenderer.getTableCellRendererComponent(table, prototypeValue, false, false, 0, -1); prototypeWidth = comp.getPreferredSize().width; } return prototypeWidth; }
ColumnFactory factory = new ColumnFactory() { @Override public void configureTableColumn(TableModel model, TableColumnExt column) { super.configureTableColumn(model, column); if (... your condition to disable sortable) { column.setSortable(false); } } } table.setColumnFactory(factory); table.setModel(model);
/** * Returns the shared default factory. * * @return the shared instance of <code>ColumnFactory</code> * @see #setInstance(ColumnFactory) */ public static synchronized ColumnFactory getInstance() { if (columnFactory == null) { columnFactory = new ColumnFactory(); } return columnFactory; }
@Override protected int getRowCount(final JXTable table) { final int rowCount = super.getRowCount(table); final int maxRowCount = ((HistoryReferencesTable) table).getMaximumRowsForTableConfiguration(); if (maxRowCount > 0 && rowCount > maxRowCount) { return maxRowCount; } return rowCount; }
if (!columnExt.isVisible()) throw new IllegalStateException("column must be visible to pack"); int column = table.convertColumnIndexToView(columnExt.getModelIndex()); int width = 0; TableCellRenderer headerRenderer = getHeaderRenderer(table, columnExt); if (headerRenderer != null) { Component comp = headerRenderer.getTableCellRendererComponent(table, columnExt.getHeaderValue(), false, false, 0, column); width = comp.getPreferredSize().width; TableCellRenderer renderer = getCellRenderer(table, columnExt); for (int r = 0; r < getRowCount(table); r++) { Component comp = table.prepareRenderer(renderer, r, column); margin = getDefaultPackMargin();
/** * Creates and adds <code>TableColumn</code>s for each column of the table * model. * <p> * * */ private void createAndAddColumns() { /* * PENDING: go the whole distance and let the factory decide which model * columns to map to view columns? That would introduce an collection * managing operation into the factory, sprawling? Can't (and probably * don't want to) move all collection related operations over - the * ColumnFactory relies on TableColumnExt type columns, while the * JXTable has to cope with all the base types. */ for (int i = 0; i < getModel().getColumnCount(); i++) { // add directly to columnModel - don't go through this.addColumn // to guarantee full control of ColumnFactory // addColumn has the side-effect to set the header! TableColumnExt tableColumn = getColumnFactory() .createAndConfigureTableColumn(getModel(), i); if (tableColumn != null) { getColumnModel().addColumn(tableColumn); } } }
int prefWidth = 75 - table.getColumnMargin(); int prototypeWidth = calcPrototypeWidth(table, columnExt); if (prototypeWidth > 0) { prefWidth = prototypeWidth; int headerWidth = calcHeaderWidth(table, columnExt); prefWidth = Math.max(prefWidth, headerWidth); prefWidth += table.getColumnModel().getColumnMargin(); columnExt.setPreferredWidth(prefWidth);
/** * Measures and returns the preferred width of the rendering component * configured with the prototype value, if any. Returns -1 if not * applicable. * * @param table the component the renderer lives in * @param columnExt the TableColumn to configure * @return the preferred width of the prototype or -1 if none. */ protected int calcPrototypeWidth(JXTable table, TableColumnExt columnExt) { int prototypeWidth = -1; Object prototypeValue = columnExt.getPrototypeValue(); if (prototypeValue != null) { // calculate how much room the prototypeValue requires TableCellRenderer cellRenderer = getCellRenderer(table, columnExt); Component comp = cellRenderer.getTableCellRendererComponent(table, prototypeValue, false, false, 0, -1); prototypeWidth = comp.getPreferredSize().width; } return prototypeWidth; }
/** * Returns the shared default factory. * * @return the shared instance of <code>ColumnFactory</code> * @see #setInstance(ColumnFactory) */ public static synchronized ColumnFactory getInstance() { if (columnFactory == null) { columnFactory = new ColumnFactory(); } return columnFactory; }
if (!columnExt.isVisible()) throw new IllegalStateException("column must be visible to pack"); int column = table.convertColumnIndexToView(columnExt.getModelIndex()); int width = 0; TableCellRenderer headerRenderer = getHeaderRenderer(table, columnExt); if (headerRenderer != null) { Component comp = headerRenderer.getTableCellRendererComponent(table, columnExt.getHeaderValue(), false, false, 0, column); width = comp.getPreferredSize().width; TableCellRenderer renderer = getCellRenderer(table, columnExt); for (int r = 0; r < getRowCount(table); r++) { Component comp = table.prepareRenderer(renderer, r, column); margin = getDefaultPackMargin();
/** * Creates and adds <code>TableColumn</code>s for each column of the table * model. * <p> * * */ private void createAndAddColumns() { /* * PENDING: go the whole distance and let the factory decide which model * columns to map to view columns? That would introduce an collection * managing operation into the factory, sprawling? Can't (and probably * don't want to) move all collection related operations over - the * ColumnFactory relies on TableColumnExt type columns, while the * JXTable has to cope with all the base types. */ for (int i = 0; i < getModel().getColumnCount(); i++) { // add directly to columnModel - don't go through this.addColumn // to guarantee full control of ColumnFactory // addColumn has the side-effect to set the header! TableColumnExt tableColumn = getColumnFactory() .createAndConfigureTableColumn(getModel(), i); if (tableColumn != null) { getColumnModel().addColumn(tableColumn); } } }
int prefWidth = 75 - table.getColumnMargin(); int prototypeWidth = calcPrototypeWidth(table, columnExt); if (prototypeWidth > 0) { prefWidth = prototypeWidth; int headerWidth = calcHeaderWidth(table, columnExt); prefWidth = Math.max(prefWidth, headerWidth); prefWidth += table.getColumnModel().getColumnMargin(); columnExt.setPreferredWidth(prefWidth);