javax.swing.table.TableColumnModel.getColumnCount()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中javax.swing.table.TableColumnModel.getColumnCount()方法的一些代码示例,展示了TableColumnModel.getColumnCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TableColumnModel.getColumnCount()方法的具体详情如下:
包路径:javax.swing.table.TableColumnModel
类名称:TableColumnModel
方法名:getColumnCount

TableColumnModel.getColumnCount介绍

暂无

代码示例

代码示例来源:origin: alibaba/druid

public int getHeaderHeight() {
  int height = 0;
  TableColumnModel columnModel = header.getColumnModel();
  for (int column = 0; column < columnModel.getColumnCount(); column++) {
    TableColumn aColumn = columnModel.getColumn(column);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    if (renderer == null) {

代码示例来源:origin: RipMeApp/ripme

historyTable.addMouseListener(new HistoryMenuMouseListener());
historyTable.setAutoCreateRowSorter(true);
for (int i = 0; i < historyTable.getColumnModel().getColumnCount(); i++) {
  int width = 130; // Default
  switch (i) {
    break;
  historyTable.getColumnModel().getColumn(i).setPreferredWidth(width);

代码示例来源:origin: ron190/jsql-injection

/**
 *  Adjust the widths of all the columns in the table
 */
public void adjustColumns() {
  TableColumnModel tcm = this.tableAdjust.getColumnModel();
  for (int i = 0 ; i < tcm.getColumnCount() ; i++) {
    this.adjustColumn(i);
  }
}

代码示例来源:origin: stackoverflow.com

tcm = table.getColumnModel();
hiddenColumns = new HashMap();
TableColumn column = tcm.getColumn(index);
hiddenColumns.put(columnName, column);
hiddenColumns.put(":" + columnName, new Integer(index));
int lastColumn = tcm.getColumnCount() - 1;
if (column < lastColumn) {
  tcm.moveColumn(lastColumn, column);

代码示例来源:origin: stackoverflow.com

Cursor cursor = header.getCursor();
if (columnIndex == tcm.getColumnCount() - 1
&&  cursor == Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR))
  column = tcm.getColumn( columnIndex );
  columnWidth = column.getWidth();
  pressedX = e.getX();

代码示例来源:origin: stackoverflow.com

public void paint(Graphics g, JComponent c) {
  Rectangle clipBounds = g.getClipBounds();
  if (header.getColumnModel().getColumnCount() == 0) {
    return;
  TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
  TableCellRenderer renderer = aColumn.getHeaderRenderer();
  if (renderer == null) {
  int headerHeight = 0;
  TableColumnModel columnModel = header.getColumnModel();
  for (int column = 0; column < columnModel.getColumnCount(); column++) {
    TableColumn aColumn = columnModel.getColumn(column);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    if (renderer == null) {
  width += columnModel.getColumnMargin() * columnModel.getColumnCount();
  if (width > Integer.MAX_VALUE) {
    width = Integer.MAX_VALUE;

代码示例来源:origin: magefree/mage

public static void saveColumnWidthAndOrderToPrefs(JTable table, String widthPrefKey, String orderPrefKey) {
  StringBuilder columnWidthSettings = new StringBuilder();
  StringBuilder columnOrderSettings = new StringBuilder();
  boolean firstValue = true;
  for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
    TableColumn column = table.getColumnModel().getColumn(table.convertColumnIndexToView(i));
    if (!firstValue) {
      columnWidthSettings.append(',');
      columnOrderSettings.append(',');
    } else {
      firstValue = false;
    }
    columnWidthSettings.append(column.getWidth());
    columnOrderSettings.append(table.convertColumnIndexToModel(i));
  }
  PreferencesDialog.saveValue(widthPrefKey, columnWidthSettings.toString());
  PreferencesDialog.saveValue(orderPrefKey, columnOrderSettings.toString());
}

代码示例来源:origin: winder/Universal-G-Code-Sender

/**
 * Helper function to set preferred widths as a percentage.
 * http://stackoverflow.com/questions/1046005/jtable-column-resize-isnt-working
 */
private void setPreferredColumnWidths(double[] percentages) {
  Dimension tableDim = getPreferredSize();
  double total = 0;
  for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
    total += percentages[i];
  }
  for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
    TableColumn column = getColumnModel().getColumn(i);
    column.setPreferredWidth(
       (int)(tableDim.width * (percentages[i] / total)));
  }
}

代码示例来源:origin: ron190/jsql-injection

/**
 *  Restore the widths of the columns in the table to its previous width
 */
public void restoreColumns() {
  TableColumnModel tcm = this.tableAdjust.getColumnModel();
  for (int i = 0 ; i < tcm.getColumnCount() ; i++) {
    this.restoreColumn(i);
  }
}

代码示例来源:origin: stackoverflow.com

this.tcm = table.getColumnModel();
TableColumn column = tcm.getColumn(index);
IndexedColumn ic = new IndexedColumn(index, column);
if (hidden.put(columnName, ic) != null) {
if (ic != null) {
  tcm.addColumn(ic.column);
  int lastColumn = tcm.getColumnCount() - 1;
  if (ic.index < lastColumn) {
    tcm.moveColumn(lastColumn, ic.index);

代码示例来源:origin: stackoverflow.com

TableColumnModel tcm = getColumnModel();
for (int i = 0; i < tcm.getColumnCount(); i++)
  TableColumn tc = tcm.getColumn(i);
  tc.setPreferredWidth( tc.getWidth() );

代码示例来源:origin: com.alibaba/druid

public int getHeaderHeight() {
  int height = 0;
  TableColumnModel columnModel = header.getColumnModel();
  for (int column = 0; column < columnModel.getColumnCount(); column++) {
    TableColumn aColumn = columnModel.getColumn(column);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    if (renderer == null) {

代码示例来源:origin: com.synaptix/SynaptixSwing

/**
 * Returns the number of accessible children in the object. If all of
 * the children of this object implement Accessible, than this method
 * should return the number of children of this object.
 * 
 * @return the number of accessible children in the object.
 */
public int getAccessibleChildrenCount() {
  return JSyTableFooter.this.table.getColumnModel().getColumnCount();
}

代码示例来源:origin: magefree/mage

public static void setColumnWidthAndOrder(JTable table, int[] defaultColumnsWidth, String widthPrefKey, String orderPrefKey) {
  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  // set the column width from saved value or defaults
  int[] widths = getIntArrayFromString(PreferencesDialog.getCachedValue(widthPrefKey, null));
  int i = 0;
  for (int width : defaultColumnsWidth) {
    if (widths != null && widths.length > i) {
      width = widths[i];
    }
    if (table.getColumnModel().getColumnCount() >= i) {
      TableColumn column = table.getColumnModel().getColumn(i++);
      column.setWidth(width);
      column.setPreferredWidth(width);
    } else {
      break;
    }
  }
  // set the column order
  int[] order = getIntArrayFromString(PreferencesDialog.getCachedValue(orderPrefKey, null));
  if (order != null && order.length == table.getColumnCount()) {
    for (int j = 0; j < table.getColumnCount(); j++) {
      table.moveColumn(table.convertColumnIndexToView(order[j]), j);
    }
  }
}

代码示例来源:origin: com.eas.platypus/platypus-js-grid

private int getTableColumnIndex(TableColumnModel aColumnModel, TableColumn aTableColumn) {
  for (int i = 0; i < aColumnModel.getColumnCount(); i++) {
    if (aColumnModel.getColumn(i) == aTableColumn) {
      return i;
    }
  }
  return -1;
}

代码示例来源:origin: kaikramer/keystore-explorer

public void restoreColumns() {
  TableColumnModel tcm = table.getColumnModel();
  for (int i = 0; i < tcm.getColumnCount(); i++) {
    restoreColumn(i);
  }
}

代码示例来源:origin: stackoverflow.com

{"eeeeeee", "aaaaaa", "bbbbbb", "cccccc", "dddddd",}};
private JTable table = new JTable(new DefaultTableModel(data, columnNames));
private TableColumnModel tcm = table.getColumnModel();
private Stack<TableColumn> colDeleted = new Stack<TableColumn>();
private JButton restoreButton = new JButton("Restore Column Size");
  table.setFont(new Font("SansSerif", Font.BOLD + Font.PLAIN, 20));
  JScrollPane scrollPane = new JScrollPane(table);
  for (int i = 0; i < (tcm.getColumnCount()); i++) {
    tcm.getColumn(i).setPreferredWidth(100);
      tcm.getColumn(2).setPreferredWidth(100);
      tcm.getColumn(2).setPreferredWidth(000);
        TableColumn colToDelete = table.getColumnModel().getColumn(table.getColumnCount() - 1);
        table.removeColumn(colToDelete);
        table.validate();

代码示例来源:origin: com.eas.platypus/platypus-js-forms

public ModelColumn[] getColumns() {
  ModelColumn[] res = new ModelColumn[columnModel.getColumnCount()];
  for (int i = 0; i < res.length; i++) {
    res[i] = (ModelColumn) columnModel.getColumn(i);
  }
  return res;
}

代码示例来源:origin: kaikramer/keystore-explorer

public void adjustColumns() {
  TableColumnModel tcm = table.getColumnModel();
  for (int i = 0; i < tcm.getColumnCount(); i++) {
    adjustColumn(i);
  }
}

代码示例来源:origin: stackoverflow.com

{"eeeeeee", "aaaaaa", "bbbbbb", "cccccc", "dddddd",}};
private JTable table = new JTable(new DefaultTableModel(data, columnNames));
private TableColumnModel tcm = table.getColumnModel();
private Stack<TableColumn> colDeleted = new Stack<TableColumn>();
private JButton restoreButton = new JButton("Restore Column Size");
  table.setFont(new Font("SansSerif", Font.BOLD + Font.PLAIN, 20));
  JScrollPane scrollPane = new JScrollPane(table);
  for (int i = 0; i < (tcm.getColumnCount()); i++) {
    tcm.getColumn(i).setPreferredWidth(150);
      tcm.getColumn(2).setPreferredWidth(100);
      tcm.getColumn(2).setPreferredWidth(000);
    public void actionPerformed(ActionEvent e) {
      if (table.getColumnCount() > 0) {
        TableColumn colToDelete = table.getColumnModel().getColumn(table.getColumnCount() - 1);
        table.removeColumn(colToDelete);
        table.validate();

相关文章