@Override protected void customizeParametersTable( TableView<ParameterTableModelItemBase<ParameterInfoImpl>> table) { final JTable t = table.getComponent(); final TableColumn defaultValue = t.getColumnModel().getColumn(2); final TableColumn varArg = t.getColumnModel().getColumn(3); t.removeColumn(defaultValue); t.removeColumn(varArg); t.getModel() .addTableModelListener( new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.INSERT) { t.getModel().removeTableModelListener(this); final TableColumnAnimator animator = new TableColumnAnimator(t); animator.setStep(48); animator.addColumn(defaultValue, (t.getWidth() - 48) / 3); animator.addColumn(varArg, 48); animator.startAndDoWhenDone( new Runnable() { @Override public void run() { t.editCellAt(t.getRowCount() - 1, 0); } }); animator.start(); } } }); }
private static int calcMaxWidth(JTable table) { int colsNum = table.getColumnModel().getColumnCount(); int totalWidth = 0; for (int col = 0; col < colsNum - 1; col++) { TableColumn column = table.getColumnModel().getColumn(col); int preferred = column.getPreferredWidth(); int width = Math.max(preferred, columnMaxWidth(table, col)); totalWidth += width; column.setMinWidth(width); column.setMaxWidth(width); column.setWidth(width); column.setPreferredWidth(width); } totalWidth += columnMaxWidth(table, colsNum - 1); return totalWidth; }
@NotNull private static MyModel setTableModel( @NotNull JTable table, @NotNull UsageViewImpl usageView, @NotNull final List<UsageNode> data) { ApplicationManager.getApplication().assertIsDispatchThread(); final int columnCount = calcColumnCount(data); MyModel model = table.getModel() instanceof MyModel ? (MyModel) table.getModel() : null; if (model == null || model.getColumnCount() != columnCount) { model = new MyModel(data, columnCount); table.setModel(model); ShowUsagesTableCellRenderer renderer = new ShowUsagesTableCellRenderer(usageView); for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setCellRenderer(renderer); } } return model; }
private static int columnMaxWidth(@NotNull JTable table, int col) { TableColumn column = table.getColumnModel().getColumn(col); int width = 0; for (int row = 0; row < table.getRowCount(); row++) { Component component = table.prepareRenderer(column.getCellRenderer(), row, col); int rendererWidth = component.getPreferredSize().width; width = Math.max(width, rendererWidth + table.getIntercellSpacing().width); } return width; }