Java Code Examples for javax.swing.table.TableColumnModel#removeColumn()

The following examples show how to use javax.swing.table.TableColumnModel#removeColumn() . 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: TaskListTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void createDefaultColumnsFromModel() {
    TableModel m = getModel();
    if( m != null ) {
        // Remove any current columns
        TableColumnModel cm = getColumnModel();
        while( cm.getColumnCount() > 0 ) {
            cm.removeColumn( cm.getColumn(0) );
 }

        // Create new columns from the data model info
        for( int i=0; i<m.getColumnCount(); i++ ) {
            TableColumn newColumn = new MyTableColumn(i);
            if( i == TaskListModel.COL_LOCATION )
                newColumn.setCellRenderer( new LeftDotRenderer() );
            else if( i != TaskListModel.COL_GROUP )
                newColumn.setCellRenderer( new TooltipRenderer() );
            addColumn(newColumn);
        }
    }
}
 
Example 2
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
/**
 * deletes all selected columns if it is not present in the <code>exp</code>
 * List
 *
 * @param table the table to DELETE columns
 * @param exp columns to avoid deleting
 * @see #deletecol(javax.swing.JTable, int)
 */
static void deletecols(JTable table, int[] exp) {
    Integer[] selcols;
    try {
        TableColumnModel tcm = table.getColumnModel();
        selcols = ArrayUtils.toObject(table.getSelectedColumns());
        Arrays.sort(selcols, Collections.reverseOrder());
        List<Integer> explist = Ints.asList(exp);
        for (int i : selcols) {
            if (!explist.contains(i)) {
                tcm.removeColumn(tcm.getColumn(i));
            }
        }

    } catch (Exception e) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, e);
    }

}
 
Example 3
Source File: EditableTableHeader.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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 4
Source File: LogTable.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 5
Source File: LogTable.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 6
Source File: SwingExtensions.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an {@link java.util.Iterator} which traverses the TableColumnModel one TableColumn at a time.
 *
 * @param self a TableColumnModel
 * @return an Iterator for a TableColumnModel
 * @since 1.6.4
 */
public static Iterator<TableColumn> iterator(final TableColumnModel self) {
    return new Iterator<TableColumn>() {
        private int index = 0;

        public boolean hasNext() {
            return index > -1 && index < self.getColumnCount();
        }

        public TableColumn next() {
            return self.getColumn(index++);
        }

        public void remove() {
            if (hasNext()) self.removeColumn(self.getColumn(index--));
        }
    };
}
 
Example 7
Source File: TableEditor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates default columns for the table from the data model using the <code>getColumnCount</code> method defined in
 * the <code>TableModel</code> interface.
 * <p/>
 * Clears any existing columns before creating the new columns based on information from the model.
 *
 * @see #getAutoCreateColumnsFromModel
 */
public void createDefaultColumnsFromModel() {
  final TableModel m = getModel();
  if ( m != null ) {
    // Remove any current columns
    final TableColumnModel cm = getColumnModel();
    while ( cm.getColumnCount() > 0 ) {
      cm.removeColumn( cm.getColumn( 0 ) );
    }

    // Create new columns from the data model info
    for ( int i = 0; i < m.getColumnCount(); i++ ) {
      if ( i == 0 ) {
        final TableColumn column = new TableColumn( i );
        column.setCellRenderer( tableHeader.getDefaultRenderer() );
        addColumn( column );
        continue;
      }

      final EditableHeaderTableColumn newColumn = new EditableHeaderTableColumn( i );
      newColumn.setHeaderEditor( new TypedHeaderCellEditor() );
      addColumn( newColumn );
    }
  }
}
 
Example 8
Source File: EditableHeader.java    From chipster with MIT License 6 votes vote down vote up
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 9
Source File: TableViewTopComponent.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static void removeColumns(final JTable table) {
    final TableColumnModel tcm = table.getColumnModel();
    while (tcm.getColumnCount() > 0) {
        final TableColumn tc = tcm.getColumn(0);
        tcm.removeColumn(tc);
    }
}
 
Example 10
Source File: OutlineViewOrderingTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testRemoveNodeColumn() throws InterruptedException, IllegalAccessException, InvocationTargetException {

        final TableColumnModel model = view.getOutline().getColumnModel();
        model.removeColumn(model.getColumn(0));
        assertEquals("One column visible", 1, model.getColumnCount());

        component.addNotify();
        final Node n0 = rootNode.getChildren().getNodeAt(0);

        rootNode.getChildren().remove(new Node[] { n0});
        assertEquals("One column visible after remove", 1, model.getColumnCount());
        rootNode.getChildren().add(new Node[] { n0});
        assertEquals("One column visible after add", 1, model.getColumnCount());
    }
 
Example 11
Source File: Options.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
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 String cNames[] = new String[table.getColumnCount()];
    final Object cols[] = new Object[table.getColumnCount()];

    for (int i = 0; i < cNames.length; i++) {
        cNames[i] = table.getColumnName(i);
        cols[i] = table.getColumnModel().getColumn(i);
    }

    for (final String element : cNames) {
        final int width = getInteger(name + "_col_" + element + "_width",
                table.getColumn(element).getWidth(), properties);
        table.getColumn(element).setPreferredWidth(width);
    }

    final TableColumnModel cm = table.getColumnModel();
    final int tci[] = new int[cNames.length];
    for (int i = 0; i < cNames.length; i++)
        cm.removeColumn((TableColumn) cols[i]);

    for (int i = 0; i < cNames.length; i++) {
        tci[i] = getInteger(name + "_col_" + cNames[i] + "_index", i,
                properties);
    }

    for (int i = 0; i < cNames.length; i++)
        for (int j = 0; j < cNames.length; j++)
            if (tci[j] == i)
                cm.addColumn((TableColumn) cols[j]);

}
 
Example 12
Source File: LogTable.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 13
Source File: LogTable.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 14
Source File: Options.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
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]);

}