javax.swing.table.TableColumnModel#removeColumn ( )源码实例Demo

下面列出了javax.swing.table.TableColumnModel#removeColumn ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: TaskListTable.java
@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);
        }
    }
}
 
/**
 * 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);
    }

}
 
源代码3 项目: rapidminer-studio   文件: EditableTableHeader.java
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]);
	}
}
 
源代码4 项目: cacheonix-core   文件: LogTable.java
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);
}
 
源代码5 项目: cacheonix-core   文件: LogTable.java
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);
   }
 
源代码6 项目: groovy   文件: SwingExtensions.java
/**
 * 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--));
        }
    };
}
 
源代码7 项目: pentaho-reporting   文件: TableEditor.java
/**
 * 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 );
    }
  }
}
 
源代码8 项目: chipster   文件: EditableHeader.java
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]);
	}
}
 
源代码9 项目: constellation   文件: TableViewTopComponent.java
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);
    }
}
 
源代码10 项目: netbeans   文件: OutlineViewOrderingTest.java
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());
    }
 
源代码11 项目: ramus   文件: Options.java
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]);

}
 
源代码12 项目: cacheonix-core   文件: LogTable.java
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);
}
 
源代码13 项目: cacheonix-core   文件: LogTable.java
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);
}
 
源代码14 项目: ramus   文件: Options.java
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]);

}