Java Code Examples for javax.swing.table.TableColumnModel#addColumn()
The following examples show how to use
javax.swing.table.TableColumnModel#addColumn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkillPointTableModel.java From pcgen with GNU Lesser General Public License v2.1 | 7 votes |
public static void initializeTable(JTable table) { table.setAutoCreateColumnsFromModel(false); JTableHeader header = table.getTableHeader(); TableColumnModel columns = new DefaultTableColumnModel(); TableCellRenderer headerRenderer = header.getDefaultRenderer(); columns.addColumn(Utilities.createTableColumn(0, "in_level", headerRenderer, false)); columns.addColumn(Utilities.createTableColumn(1, "in_class", headerRenderer, true)); TableColumn remainCol = Utilities.createTableColumn(2, "in_iskRemain", headerRenderer, false); remainCol.setCellRenderer(new BoldNumberRenderer()); columns.addColumn(remainCol); columns.addColumn(Utilities.createTableColumn(3, "in_gained", headerRenderer, false)); table.setDefaultRenderer(Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.CENTER)); table.setColumnModel(columns); table.setFocusable(false); header.setReorderingAllowed(false); header.setResizingAllowed(false); }
Example 2
Source File: TableViewTopComponent.java From constellation with Apache License 2.0 | 6 votes |
private void setDefaultColumns(final JTable table) { final GraphTableModel model = (GraphTableModel) table.getModel(); final TableColumnModel tcm = table.getColumnModel(); // A blank graph with no attributes still has dummy attributes in the table model. // When new attributes are added, we only only want to add them to the table if the only // existing attributes are dummies. final boolean addDefaults = currentElementType == GraphElementType.VERTEX && tcm.getColumnCount() <= 1 || currentElementType == GraphElementType.TRANSACTION && tcm.getColumnCount() <= 3; if (addDefaults) { for (int index = 0; index < model.getColumnCount(); index++) { final String name = model.getColumnName(index); if (isImportant(name)) { final TableColumn tc = new TableColumn(index); tc.setHeaderValue(name); tcm.addColumn(tc); } } } }
Example 3
Source File: EditableHeader.java From chipster with MIT License | 6 votes |
protected void recreateTableColumn(TableColumnModel columnModel) { int n = columnModel.getColumnCount(); EditableHeaderTableColumn[] newCols = new EditableHeaderTableColumn[n]; TableColumn[] oldCols = new TableColumn[n]; for (int i=0;i<n;i++) { oldCols[i] = columnModel.getColumn(i); newCols[i] = new EditableHeaderTableColumn(); newCols[i].copyValues(oldCols[i]); } for (int i=0;i<n;i++) { columnModel.removeColumn(oldCols[i]); } for (int i=0;i<n;i++) { columnModel.addColumn(newCols[i]); } }
Example 4
Source File: ClassLevelTableModel.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
public static void initializeTable(JTable classLevelTable) { JTableHeader tableHeader = classLevelTable.getTableHeader(); tableHeader.setResizingAllowed(false); tableHeader.setReorderingAllowed(false); TableColumnModel columnModel = new DefaultTableColumnModel(); TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer(); columnModel.addColumn(Utilities.createTableColumn(0, "Level", headerRenderer, false)); columnModel.addColumn(Utilities.createTableColumn(1, "HP", headerRenderer, false)); columnModel.addColumn(Utilities.createTableColumn(2, "Class (All Levels In Class)", headerRenderer, true)); classLevelTable.setColumnModel(columnModel); classLevelTable.setAutoCreateColumnsFromModel(false); classLevelTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); classLevelTable.setFocusable(false); classLevelTable.setCellSelectionEnabled(false); classLevelTable.setRowHeight(20); }
Example 5
Source File: SkillPointTableModel.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
public static void initializeTable(JTable table) { table.setAutoCreateColumnsFromModel(false); JTableHeader header = table.getTableHeader(); TableColumnModel columns = new DefaultTableColumnModel(); TableCellRenderer headerRenderer = header.getDefaultRenderer(); columns.addColumn(Utilities.createTableColumn(0, "in_level", headerRenderer, false)); columns.addColumn(Utilities.createTableColumn(1, "in_class", headerRenderer, true)); TableColumn remainCol = Utilities.createTableColumn(2, "in_iskRemain", headerRenderer, false); remainCol.setCellRenderer(new BoldNumberRenderer()); columns.addColumn(remainCol); columns.addColumn(Utilities.createTableColumn(3, "in_gained", headerRenderer, false)); table.setDefaultRenderer(Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.CENTER)); table.setColumnModel(columns); table.setFocusable(false); header.setReorderingAllowed(false); header.setResizingAllowed(false); }
Example 6
Source File: UpdateSummaryTable.java From bigtable-sql with Apache License 2.0 | 6 votes |
public UpdateSummaryTable(List<ArtifactStatus> artifactStatus, UpdateSummaryTableModel model) { super(model); _model = model; _artifacts = artifactStatus; setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); getTableHeader().setResizingAllowed(true); getTableHeader().setReorderingAllowed(true); setAutoCreateColumnsFromModel(false); setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN); final TableColumnModel tcm = new DefaultTableColumnModel(); JComboBox _actionComboBox = new JComboBox(); for (int i = 0; i < model.getColumnCount(); ++i) { final TableColumn col = new TableColumn(i, model.getColumnWidth(i)); col.setHeaderValue(model.getColumnName(i)); if (i == 3) { col.setCellEditor(new DefaultCellEditor(initCbo(_actionComboBox))); } tcm.addColumn(col); } setColumnModel(tcm); initPopup(); }
Example 7
Source File: EditableTableHeader.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
protected void recreateTableColumn(TableColumnModel columnModel) { int n = columnModel.getColumnCount(); EditableTableHeaderColumn[] newCols = new EditableTableHeaderColumn[n]; TableColumn[] oldCols = new TableColumn[n]; for (int i = 0; i < n; i++) { oldCols[i] = columnModel.getColumn(i); newCols[i] = new EditableTableHeaderColumn(i); newCols[i].copyValues(oldCols[i]); } for (int i = 0; i < n; i++) { columnModel.removeColumn(oldCols[i]); } for (int i = 0; i < n; i++) { columnModel.addColumn(newCols[i]); } }
Example 8
Source File: LogTable.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void setView(List columns) { TableColumnModel model = getColumnModel(); // Remove all the columns: for (int f = 0; f < _numCols; f++) { model.removeColumn(_tableColumns[f]); } Iterator selectedColumns = columns.iterator(); Vector columnNameAndNumber = getColumnNameAndNumber(); while (selectedColumns.hasNext()) { // add the column to the view model.addColumn(_tableColumns[columnNameAndNumber.indexOf(selectedColumns.next())]); } //SWING BUG: sizeColumnsToFit(-1); }
Example 9
Source File: PluginSummaryTable.java From bigtable-sql with Apache License 2.0 | 6 votes |
public PluginSummaryTable(PluginInfo[] pluginInfo, PluginStatus[] pluginStatus) { super(new MyTableModel(pluginInfo, pluginStatus)); setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); getTableHeader().setResizingAllowed(true); getTableHeader().setReorderingAllowed(true); setAutoCreateColumnsFromModel(false); setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN); final TableColumnModel tcm = new DefaultTableColumnModel(); for (int i = 0; i < s_columnWidths.length; ++i) { final TableColumn col = new TableColumn(i, s_columnWidths[i]); col.setHeaderValue(s_hdgs[i]); tcm.addColumn(col); } setColumnModel(tcm); }
Example 10
Source File: LogTable.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public final void setView(final List columns) { final TableColumnModel model = getColumnModel(); // Remove all the columns: for (int f = 0; f < _numCols; f++) { model.removeColumn(_tableColumns[f]); } final Iterator selectedColumns = columns.iterator(); final Vector columnNameAndNumber = getColumnNameAndNumber(); while (selectedColumns.hasNext()) { // add the column to the view model.addColumn(_tableColumns[columnNameAndNumber.indexOf(selectedColumns.next())]); } //SWING BUG: sizeColumnsToFit(-1); }
Example 11
Source File: ProductEntryTableModel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
public TableColumnModel getColumnModel() { final TableColumnModel columnModel = new DefaultTableColumnModel(); for (TableColumn aColumnList : columnList) { columnModel.addColumn(aColumnList); } return columnModel; }
Example 12
Source File: OverviewCtrl.java From bigtable-sql with Apache License 2.0 | 5 votes |
private void initScaleTable(DataScale[] scales, List<Object[]> rows, ColumnDisplayDefinition[] columnDefinitions, boolean keepFormerParent, CallDepthComboModel callDepth) { DataScaleTableModel dataScaleTableModel = new DataScaleTableModel(scales, callDepth); DataScaleTable dataScaleTable = new DataScaleTable(dataScaleTableModel, rows, columnDefinitions); TableColumnModel tcm = new DefaultTableColumnModel(); dataScaleTable.setColumnModel(tcm); for (int i = 0; i < DataScaleTableModel.getColumnNames().length; i++) { TableColumn col = new TableColumn(i); col.setHeaderValue(DataScaleTableModel.getColumnNames()[i]); if (DataScaleTableModel.COL_NAME_COLUMN.equals(DataScaleTableModel.getColumnNames()[i])) { col.setPreferredWidth(DataScaleTableColumnWidthsPersister.getColumnWidthForColName(DataScaleTableModel.COL_NAME_COLUMN)); } else if (DataScaleTableModel.COL_NAME_DATA.equals(DataScaleTableModel.getColumnNames()[i])) { col.setPreferredWidth(DataScaleTableColumnWidthsPersister.getColumnWidthForColName(DataScaleTableModel.COL_NAME_DATA)); } tcm.addColumn(col); } _overviewHolder.setOverview(dataScaleTable, keepFormerParent); initGui(); }
Example 13
Source File: AOITableModel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
public TableColumnModel getColumnModel() { final TableColumnModel columnModel = new DefaultTableColumnModel(); for (TableColumn aColumnList : columnList) { columnModel.addColumn(aColumnList); } return columnModel; }
Example 14
Source File: LogTable.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public final void setDetailedView() { //TODO: Definable Views. final TableColumnModel model = getColumnModel(); // Remove all the columns: for (int f = 0; f < _numCols; f++) { model.removeColumn(_tableColumns[f]); } // Add them back in the correct order: for (int i = 0; i < _numCols; i++) { model.addColumn(_tableColumns[i]); } //SWING BUG: sizeColumnsToFit(-1); }
Example 15
Source File: LogTable.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void setDetailedView() { //TODO: Defineable Views. TableColumnModel model = getColumnModel(); // Remove all the columns: for (int f = 0; f < _numCols; f++) { model.removeColumn(_tableColumns[f]); } // Add them back in the correct order: for (int i = 0; i < _numCols; i++) { model.addColumn(_tableColumns[i]); } //SWING BUG: sizeColumnsToFit(-1); }
Example 16
Source File: Options.java From ramus with GNU General Public License v3.0 | 4 votes |
public static void getJTableOptions(final String name, final JTable table, final Properties properties) { final Integer colCount = getObjectInteger(name + "_col_count", properties); if (colCount == null || colCount.intValue() != table.getColumnCount()) return; final Object cols[] = new Object[table.getColumnCount()]; for (int i = 0; i < colCount.intValue(); i++) { cols[i] = table.getColumnModel().getColumn( table.convertColumnIndexToView(i)); } for (int i = 0; i < colCount.intValue(); i++) { try { int index = table.convertColumnIndexToView(i); final int width = getInteger(name + "_col_" + i + "_width", table.getColumnModel().getColumn(index).getWidth(), properties); table.getColumnModel().getColumn(index) .setPreferredWidth(width); } catch (Exception e) { } } final TableColumnModel cm = table.getColumnModel(); final int tci[] = new int[colCount.intValue()]; for (int i = 0; i < colCount.intValue(); i++) cm.removeColumn((TableColumn) cols[i]); for (int i = 0; i < colCount.intValue(); i++) { tci[i] = getInteger(name + "_col_" + i + "_index", i, properties); } for (int i = 0; i < colCount.intValue(); i++) for (int j = 0; j < colCount.intValue(); j++) if (tci[j] == i) cm.addColumn((TableColumn) cols[j]); }
Example 17
Source File: TraceTableModel.java From pega-tracerviewer with Apache License 2.0 | 3 votes |
@Override protected TableColumnModel getTableColumnModel() { TableColumnModel tableColumnModel = new DefaultTableColumnModel(); for (int i = 0; i < getColumnCount(); i++) { TableColumn tableColumn = new TableColumn(i); String text = getColumnName(i); tableColumn.setHeaderValue(text); TraceTableModelColumn ttmc = getColumn(i); TraceTableCellRenderer ttcr = new TraceTableCellRenderer(); ttcr.setBorder(new EmptyBorder(1, 3, 1, 1)); ttcr.setHorizontalAlignment(ttmc.getHorizontalAlignment()); tableColumn.setCellRenderer(ttcr); int colWidth = ttmc.getPrefColumnWidth(); tableColumn.setPreferredWidth(colWidth); // tableColumn.setMinWidth(colWidth); tableColumn.setWidth(colWidth); tableColumn.setResizable(true); tableColumnModel.addColumn(tableColumn); } return tableColumnModel; }
Example 18
Source File: SwingExtensions.java From groovy with Apache License 2.0 | 2 votes |
/** * Overloads the left shift operator to provide an easy way to add * columns to a TableColumnModel. * * @param self a TableColumnModel * @param column a TableColumn to be added to the model. * @return same model, after the value was added to it. * @since 1.6.4 */ public static TableColumnModel leftShift(TableColumnModel self, TableColumn column) { self.addColumn(column); return self; }
Example 19
Source File: TraceTreeTable.java From pega-tracerviewer with Apache License 2.0 | 2 votes |
@Override protected void setTreeTableColumnModel() { TreeTableModelAdapter model = (TreeTableModelAdapter) getModel(); TableColumnModel tableColumnModel = new DefaultTableColumnModel(); for (int i = 0; i < model.getColumnCount(); i++) { TableColumn tableColumn = new TableColumn(i); TreeTableColumn treeTableColumn = model.getColumn(i); String text = treeTableColumn.getDisplayName(); Class<?> columnClass = treeTableColumn.getColumnClass(); int preferredWidth = treeTableColumn.getPrefColumnWidth(); tableColumn.setHeaderValue(text); tableColumn.setPreferredWidth(preferredWidth); TableCellRenderer tcr = null; if (TreeTableColumn.TREE_COLUMN_CLASS.equals(columnClass)) { DefaultTreeTableTree treeTableTree = getTree(); tcr = treeTableTree; tableColumn.setCellEditor(new TreeTableCellEditor(treeTableTree)); } else { TraceTreeTableCellRenderer ltcr = new TraceTreeTableCellRenderer(); ltcr.setBorder(new EmptyBorder(1, 3, 1, 1)); ltcr.setHorizontalAlignment(treeTableColumn.getHorizontalAlignment()); tableColumn.setCellEditor(new TreeTableCellEditor(ltcr)); tcr = ltcr; } tableColumn.setCellRenderer(tcr); tableColumn.setResizable(true); tableColumnModel.addColumn(tableColumn); } setColumnModel(tableColumnModel); }
Example 20
Source File: TraceTreeCombinedTable.java From pega-tracerviewer with Apache License 2.0 | 2 votes |
@Override protected void setTreeTableColumnModel() { TreeTableModelAdapter model = (TreeTableModelAdapter) getModel(); TableColumnModel tableColumnModel = new DefaultTableColumnModel(); for (int i = 0; i < model.getColumnCount(); i++) { TableColumn tableColumn = new TableColumn(i); TreeTableColumn treeTableColumn = model.getColumn(i); String text = treeTableColumn.getDisplayName(); Class<?> columnClass = treeTableColumn.getColumnClass(); int preferredWidth = treeTableColumn.getPrefColumnWidth(); tableColumn.setHeaderValue(text); tableColumn.setPreferredWidth(preferredWidth); TableCellRenderer tcr = null; if (TreeTableColumn.TREE_COLUMN_CLASS.equals(columnClass)) { DefaultTreeTableTree treeTableTree = getTree(); tcr = treeTableTree; tableColumn.setCellEditor(new TreeTableCellEditor(treeTableTree)); } else { TraceTreeTableCombinedCellRenderer ltcr = new TraceTreeTableCombinedCellRenderer(); ltcr.setBorder(new EmptyBorder(1, 3, 1, 1)); ltcr.setHorizontalAlignment(treeTableColumn.getHorizontalAlignment()); tableColumn.setCellEditor(new TreeTableCellEditor(ltcr)); tcr = ltcr; } tableColumn.setCellRenderer(tcr); tableColumn.setResizable(true); tableColumnModel.addColumn(tableColumn); } setColumnModel(tableColumnModel); }