List of usage examples for javax.swing.table TableColumn setModelIndex
@BeanProperty(description = "The model index.") public void setModelIndex(int modelIndex)
From source file:DefaultsDisplay.java
protected JTable createDefaultsTable() { JTable table = new JTable(new UIDefaultsTableModel()); table.setRowHeight(rowHeight);/*www.ja va2 s .co m*/ table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); initFilters(table); DefaultTableColumnModel columnModel = new DefaultTableColumnModel(); Color rowColors[] = new Color[2]; rowColors[0] = UIManager.getColor("Table.background"); rowColors[1] = new Color((int) (rowColors[0].getRed() * .90), (int) (rowColors[0].getGreen() * .95), (int) (rowColors[0].getBlue() * .95)); int width = 0; TableColumn column = new TableColumn(); column.setCellRenderer(new KeyRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.KEY_COLUMN); column.setHeaderValue("Key"); column.setPreferredWidth(250); columnModel.addColumn(column); width += column.getPreferredWidth(); column = new TableColumn(); column.setCellRenderer(new RowRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.TYPE_COLUMN); column.setHeaderValue("Type"); column.setPreferredWidth(250); columnModel.addColumn(column); width += column.getPreferredWidth(); column = new TableColumn(); column.setCellRenderer(new ValueRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.VALUE_COLUMN); column.setHeaderValue("Value"); column.setPreferredWidth(300); columnModel.addColumn(column); width += column.getPreferredWidth(); table.setColumnModel(columnModel); table.setPreferredScrollableViewportSize(new Dimension(width, 12 * rowHeight)); return table; }
From source file:org.isatools.isacreator.gui.formelements.SubForm.java
protected void removeColumn(int curColDelete) { if ((curColDelete == -1) || (curColDelete == 0)) { return;/*ww w.ja va2 s.c o m*/ } if (defaultTableModel.getColumnCount() == 2 && curColDelete == (defaultTableModel.getColumnCount() - 1)) { clearColumn(curColDelete); return; } else { clearColumn(curColDelete); } if (fieldType == FieldTypes.ASSAY && (dataEntryForm != null) && !uneditableRecords.contains(curColDelete)) { clearColumn(curColDelete); return; } DefaultTableModel model = (DefaultTableModel) scrollTable.getModel(); // get the column. because 1 was added on previously to take account of the first column, we need to remove // it this time since the column indexes are now coming from the table. TableColumn col = scrollTable.getColumnModel().getColumn(curColDelete - 1); int columnModelIndex = col.getModelIndex(); Vector data = model.getDataVector(); Vector<String> colIds = new Vector<String>(); for (int i = 0; i < model.getColumnCount(); i++) { colIds.addElement(model.getColumnName(i)); } scrollTable.removeColumn(col); colIds.removeElementAt(columnModelIndex); // remove any data present in the column on deletion for (Object aData : data) { Vector row = (Vector) aData; row.removeElementAt(columnModelIndex); } model.setDataVector(data, colIds); // decrease each column index after deleted column by 1 so that indexes can be kept intact. Enumeration columnEnumeration = scrollTable.getColumnModel().getColumns(); while (columnEnumeration.hasMoreElements()) { TableColumn c = (TableColumn) columnEnumeration.nextElement(); if (c.getModelIndex() >= columnModelIndex) { c.setModelIndex(c.getModelIndex() - 1); } } if (fieldType == FieldTypes.ASSAY && uneditableRecords.contains(defaultTableModel.getColumnCount() - 1)) { uneditableRecords.remove(defaultTableModel.getColumnCount() - 1); } // update the model model.fireTableStructureChanged(); updateTables(); }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Remove a column from the spreadsheet.getTable(), delete all the data associated with the column in the model, and keep indices * intact by decreasing the index of every column after the one deleted by one to stop fragmentation. * * @param model - @see SpreadsheetModel to be acted on * @param columnToRemove - @see TableColumn representing column to remove. *///w w w . j a v a 2 s.c o m private void deleteColumn(SpreadsheetModel model, TableColumn columnToRemove) { int columnModelIndex = columnToRemove.getModelIndex(); Vector data = model.getDataVector(); Vector colIds = model.getColumnIdentifiers(); spreadsheet.getTable().removeColumn(columnToRemove); colIds.removeElementAt(columnModelIndex); // remove any data present in the column on deletion for (Object aData : data) { Vector row = (Vector) aData; row.removeElementAt(columnModelIndex); } model.setDataVector(data, colIds); // decrease each column index after deleted column by 1 so that indexes can be kept intact. Enumeration spreadsheetColumns = spreadsheet.getTable().getColumnModel().getColumns(); while (spreadsheetColumns.hasMoreElements()) { TableColumn c = (TableColumn) spreadsheetColumns.nextElement(); if (c.getModelIndex() >= columnModelIndex) { c.setModelIndex(c.getModelIndex() - 1); } } // update the model model.fireTableStructureChanged(); }