List of usage examples for javax.swing.table TableColumnModel getColumnCount
public int getColumnCount();
From source file:com.aw.swing.mvp.binding.component.BndSJTable.java
public void resetHeader() { TableColumnModel colModel = jTable.getColumnModel(); int colsNumber = getColumnsInfo().length; int colsModel = colModel.getColumnCount() + fixedColumns; if (colsNumber == colsModel) { if (getSelectorColumn() != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { JTable fixedJTable = (JTable) jTable.getClientProperty(CP_FIXED_TABLE); if (fixedJTable != null) { fixedJTable.getTableHeader().repaint(); } else { jTable.getTableHeader().repaint(); }/*from w w w .ja v a 2s .c o m*/ } }); } return; } if (colsNumber > colsModel) { int delta = colsNumber - colModel.getColumnCount(); for (int i = 0; i < delta; i++) { colModel.addColumn(new TableColumn()); } } for (int i = 0; i < colsNumber; i++) { TableColumn column = colModel.getColumn(i); column.setHeaderValue(getColumnsInfo()[i].getColumnHeader()); } SwingUtilities.invokeLater(new Runnable() { public void run() { JTable fixedJTable = (JTable) jTable.getClientProperty(CP_FIXED_TABLE); if (fixedJTable != null) { fixedJTable.getTableHeader().repaint(); } jTable.getTableHeader().repaint(); } }); }
From source file:edu.ku.brc.af.ui.forms.TableViewObj.java
/** * Sets all the Columns to be center justified this COULD be set up in the table info. * */// w w w. ja v a 2 s . c om protected void configColumns() { ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.CENTER); //DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); //renderer.setHorizontalAlignment(SwingConstants.CENTER); DefaultTableCellRenderer renderer = new BiColorTableCellRenderer(true); // Centered TableColumnModel tableColModel = table.getColumnModel(); for (int i = 0; i < tableColModel.getColumnCount(); i++) { tableColModel.getColumn(i).setCellRenderer(renderer); } }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Calculates and sets the each column to it preferred size. NOTE: This * method also sets the table height to 10 rows. * /*from w w w . j a v a 2 s .co m*/ * @param table the table to fix up * @param numRowsHeight the number of rows to make the table height (or null not to set it) */ public static void calcColumnWidths(final JTable table, final Integer numRowsHeight, final Integer maxWidth) { if (table != null) { JTableHeader header = table.getTableHeader(); TableCellRenderer defaultHeaderRenderer = null; if (header != null) { defaultHeaderRenderer = header.getDefaultRenderer(); } TableColumnModel columns = table.getColumnModel(); TableModel data = table.getModel(); int margin = columns.getColumnMargin(); // only JDK1.3 int rowCount = data.getRowCount(); int totalWidth = 0; for (int i = columns.getColumnCount() - 1; i >= 0; --i) { TableColumn column = columns.getColumn(i); int columnIndex = column.getModelIndex(); int width = -1; TableCellRenderer h = column.getHeaderRenderer(); if (h == null) h = defaultHeaderRenderer; if (h != null) // Not explicitly impossible { Component c = h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, i); width = c.getPreferredSize().width; } for (int row = rowCount - 1; row >= 0; --row) { TableCellRenderer r = table.getCellRenderer(row, i); Component c = r.getTableCellRendererComponent(table, data.getValueAt(row, columnIndex), false, false, row, i); width = Math.max(width, c.getPreferredSize().width + 10); // adding an arbitray 10 pixels to make it look nicer if (maxWidth != null) { width = Math.min(width, maxWidth); } } if (width >= 0) { column.setPreferredWidth(width + margin); // <1.3: without margin } else { // ??? } totalWidth += column.getPreferredWidth(); } // If you like; This does not make sense for two many columns! Dimension size = table.getPreferredScrollableViewportSize(); //if (totalWidth > size.width) { if (numRowsHeight != null) { size.height = Math.min(size.height, table.getRowHeight() * numRowsHeight); } size.width = totalWidth; table.setPreferredScrollableViewportSize(size); } } }
From source file:org.apache.cayenne.swing.TableBinding.java
protected void resizeColumns(Object[] sampleLongValues) { TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); TableColumnModel columnModel = table.getColumnModel(); TableModel tableModel = table.getModel(); for (int i = 0; i < columnModel.getColumnCount(); i++) { TableColumn column = columnModel.getColumn(i); Component header = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);/*from w w w . j a v a 2 s . c om*/ int headerWidth = header.getPreferredSize().width; if (sampleLongValues[i] != null) { Component bigCell = table.getDefaultRenderer(tableModel.getColumnClass(i)) .getTableCellRendererComponent(table, sampleLongValues[i], false, false, 0, i); int cellWidth = bigCell.getPreferredSize().width; column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } else { column.setPreferredWidth(headerWidth); } } }
From source file:org.isatools.isacreator.gui.formelements.SubForm.java
public void updateTables() { TableColumnModel scrollColumnModel = scrollTable.getColumnModel(); if (scrollColumnModel.getColumnCount() > 0) { for (int i = 0; i < numFrozenColumns; i++) { scrollColumnModel.removeColumn(scrollColumnModel.getColumn(0)); }//from w ww . j ava 2 s . c om TableColumnModel lockedColumnModel = lockedTable.getColumnModel(); while (lockedTable.getColumnCount() > numFrozenColumns) { lockedColumnModel.removeColumn(lockedColumnModel.getColumn(numFrozenColumns)); } for (int i = 0; i < scrollTable.getColumnCount(); i++) { scrollColumnModel.getColumn(i).setPreferredWidth(100); } lockedTable.getColumnModel().getColumn(0).setPreferredWidth(250); lockedTable.setPreferredScrollableViewportSize(lockedTable.getPreferredSize()); setHeaderProperties(scrollTable, scrollTableHeaderRenderer); setHeaderProperties(lockedTable, lockedTableHeaderRenderer); } }
From source file:org.paxle.desktop.impl.dialogues.cconsole.CrawlingConsole.java
private final int[] getCurrentWidths() { final TableColumnModel tcm = table.getTableHeader().getColumnModel(); final int[] widths = new int[tcm.getColumnCount()]; for (int i = 0; i < widths.length; i++) widths[i] = tcm.getColumn(i).getWidth(); return widths; }
From source file:org.pentaho.reporting.ui.datasources.table.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/>//from w ww . j a v a 2s .c om * 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); } } }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
private void updateColumnModel() { TableColumnModel columnModel = table.getColumnModel(); totalFlex = 0;/*from w w w. ja va 2 s. co m*/ for (int i = 0; i < columns.getChildNodes().size(); i++) { if (i >= columnModel.getColumnCount()) { break; } SwingTreeCol child = (SwingTreeCol) columns.getChildNodes().get(i); TableColumn col = columnModel.getColumn(i); totalFlex += child.getFlex(); col.setHeaderValue(child.getLabel()); col.setCellEditor(getCellEditor(child)); col.setCellRenderer(getCellRenderer(child)); // List<XulComponent> cells = child.getChildNodes(); // for(int z=0; z<cells.size(); z++){ // XulComponent cell = cells.get(z); // } } }