public void setColumnMargin() { if (columnGroups == null) { return; } int columnMargin = getColumnModel().getColumnMargin(); Enumeration<ColumnGroup> enum1 = columnGroups.elements(); while (enum1.hasMoreElements()) { ColumnGroup cGroup = (ColumnGroup) enum1.nextElement(); cGroup.setColumnMargin(columnMargin); } }
private Dimension createHeaderSize(long width) { TableColumnModel columnModel = header.getColumnModel(); width += columnModel.getColumnMargin() * columnModel.getColumnCount(); if (width > Integer.MAX_VALUE) { width = Integer.MAX_VALUE; } return new Dimension((int) width, getHeaderHeight()); }
Rectangle cellRect = new Rectangle(0, 0, size.width, size.height); Hashtable<ColumnGroup, Rectangle> h = new Hashtable<ColumnGroup, Rectangle>(); int columnMargin = header.getColumnModel().getColumnMargin(); Enumeration<TableColumn> enumeration = header.getColumnModel().getColumns(); while (enumeration.hasMoreElements()) {
public static int getMaxColumnWidth(JTable table, int column) { // Set first to column header width as a minimum Font font = table.getFont(); FontMetrics metrics = table.getGraphics().getFontMetrics(font); String header = table.getColumnName(column) + " "; // Whitespace buffer as a crude way (hack) // to account for the rendering context Test.output("Column name: " + header); // Convert from string length in characters to pixels int widest = metrics.stringWidth(header) + (2 * table.getColumnModel().getColumnMargin()); Test.output("Starting widest value: " + header + " (" + widest + " pixels)"); // Now go through each row to see if there is a longer value in the column int rows = table.getRowCount(); Test.output("Row count: " + rows); for (int index = 0; index < rows; index++) { String cellValue = table.getValueAt(index, column).toString(); int cellWidth = metrics.stringWidth(cellValue) + (2 * table.getColumnModel().getColumnMargin()); if (cellWidth > widest) { widest = cellWidth; Test.output("New widest value: " + widest + " pixels"); } } return widest; }
public void setColumnMargin() { if (columnGroups == null) { return; } int columnMargin = getColumnModel().getColumnMargin(); Enumeration<ColumnGroup> enum1 = columnGroups.elements(); while (enum1.hasMoreElements()) { ColumnGroup cGroup = (ColumnGroup) enum1.nextElement(); cGroup.setColumnMargin(columnMargin); } }
private Dimension createHeaderSize(long width) { TableColumnModel columnModel = header.getColumnModel(); width += columnModel.getColumnMargin() * columnModel.getColumnCount(); if (width > Integer.MAX_VALUE) { width = Integer.MAX_VALUE; } return new Dimension((int) width, getHeaderHeight()); }
Rectangle cellRect = new Rectangle(0, 0, size.width, size.height); Hashtable<ColumnGroup, Rectangle> h = new Hashtable<ColumnGroup, Rectangle>(); int columnMargin = header.getColumnModel().getColumnMargin(); Enumeration<TableColumn> enumeration = header.getColumnModel().getColumns(); while (enumeration.hasMoreElements()) {
int columnMargin = getColumnModel().getColumnMargin(); for (ColumnGroup group : columnGroups) { group.setColumnMargin(columnMargin);
width += columnModel.getColumnMargin() * columnModel.getColumnCount(); if (width > Integer.MAX_VALUE) { width = Integer.MAX_VALUE;
@Override public void columnMarginChanged(ChangeEvent e) { Object oSource = e.getSource(); assert oSource == delegate; int oldMargin = columnMargin; columnMargin = delegate.getColumnMargin(); // Swing fires columnMarginChanged event when any column's width changes // this fact has no any reason. It seems that it's simply bad work of swing's programmers. // So, we have no any outgo, but unconditionally fire this event too. //if (oldMargin != columnMargin) { fireColumnMarginChanged(columnMargin); //} }
@Override public void columnMarginChanged(ChangeEvent e) { Object oSource = e.getSource(); assert oSource == delegate; int oldMargin = columnMargin; columnMargin = delegate.getColumnMargin(); // Swing fires columnMarginChanged event when any column's width changes // this fact has no any reason. It seems that it's simply bad work of swing's programmers. // So, we have no any outgo, but unconditionally fire this event too. //if (oldMargin != columnMargin) { fireColumnMarginChanged(columnMargin); //} }
/** * Returns the margin between columns. * <p> * * Convenience to expose column model properties through * <code>JXTable</code> api. * * @return the margin between columns * * @see #setColumnMargin(int) * @see TableColumnModel#getColumnMargin() */ public int getColumnMargin() { return getColumnModel().getColumnMargin(); }
/** * Returns the margin between columns. * <p> * * Convenience to expose column model properties through * <code>JXTable</code> api. * * @return the margin between columns * * @see #setColumnMargin(int) * @see TableColumnModel#getColumnMargin() */ public int getColumnMargin() { return getColumnModel().getColumnMargin(); }
/** * Returns the margin between columns. * <p> * * Convenience to expose column model properties through * <code>JXTable</code> api. * * @return the margin between columns * * @see #setColumnMargin(int) * @see TableColumnModel#getColumnMargin() */ public int getColumnMargin() { return getColumnModel().getColumnMargin(); }
/** * Returns the margin between columns. * <p> * * Convenience to expose column model properties through * <code>JXTable</code> api. * * @return the margin between columns * * @see #setColumnMargin(int) * @see TableColumnModel#getColumnMargin() */ public int getColumnMargin() { return getColumnModel().getColumnMargin(); }
void setRenderer(Component c, int o, int w) { impl = c; offset = o; prefWidth = w; marginOffset = isLeadingAlign(impl) ? 0 : getColumnModel().getColumnMargin(); implM = c instanceof Movable ? (Movable)c : null; }
void setModel(TableModel tableModel) { table.setModel(tableModel); if (table.getColumnCount() > 0) { final JTableHeader tableHeader = table.getTableHeader(); final int margin = tableHeader.getColumnModel().getColumnMargin(); final TableCellRenderer renderer = tableHeader.getDefaultRenderer(); final Enumeration<TableColumn> columns = table.getColumnModel().getColumns(); while (columns.hasMoreElements()) { TableColumn tableColumn = columns.nextElement(); final int width = getColumnMinWith(tableColumn, renderer, margin); tableColumn.setMinWidth(width); } } }
void setModel(TableModel tableModel) { table.setModel(tableModel); if (table.getColumnCount() > 0) { final JTableHeader tableHeader = table.getTableHeader(); final int margin = tableHeader.getColumnModel().getColumnMargin(); final TableCellRenderer renderer = tableHeader.getDefaultRenderer(); final Enumeration<TableColumn> columns = table.getColumnModel().getColumns(); while (columns.hasMoreElements()) { TableColumn tableColumn = columns.nextElement(); final int width = getColumnMinWith(tableColumn, renderer, margin); tableColumn.setMinWidth(width); } } }
protected void paintComponent(Graphics g) { // TODO: this is naive: we should take the clipping region into account and // only paint the visible rows Rectangle cellRect = new Rectangle(0,0,getWidth(),_table.getRowHeight(0)); int rowMargin = _header.getColumnModel().getColumnMargin() - 1; for (int i = 0; i < _table.getRowCount(); ++i) { int rowHeight = _table.getRowHeight(i); cellRect.height = rowHeight - rowMargin; paintCell(g, cellRect, i); cellRect.y += rowHeight; } }
protected void layoutTree() { int hier = treeTable.getHierarchicalColumn(); if (hier < 0) { tree.setBounds(0, 0, 0, 0); } else { Rectangle r = table.getCellRect(-1, hier, true); int cm = treeTable.getColumnModel().getColumnMargin(); r.x += cm/2; r.width -= cm; r.height = treeTable.getHeight(); tree.setBounds(r); } }