当前位置: 首页>>代码示例>>Java>>正文


Java TableColumn.getHeaderRenderer方法代码示例

本文整理汇总了Java中javax.swing.table.TableColumn.getHeaderRenderer方法的典型用法代码示例。如果您正苦于以下问题:Java TableColumn.getHeaderRenderer方法的具体用法?Java TableColumn.getHeaderRenderer怎么用?Java TableColumn.getHeaderRenderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.table.TableColumn的用法示例。


在下文中一共展示了TableColumn.getHeaderRenderer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initColumnWidth

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
/**
 * Initializes preferred (and eventually maximum) width of a table column
 * based on the size of its header and the estimated longest value.
 *
 * @param table Table to adjust the column width for.
 * @param index Index of the column.
 * @param longValue Estimated long value for the column.
 * @param padding Number of pixes for padding.
 */
public static void initColumnWidth(JTable table, int index, Object longValue, int padding) {
    TableColumn column = table.getColumnModel().getColumn(index);

    // get preferred size of the header
    TableCellRenderer headerRenderer = column.getHeaderRenderer();
    if (headerRenderer == null) {
        headerRenderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp = headerRenderer.getTableCellRendererComponent(
            table, column.getHeaderValue(), false, false, 0, 0);
    int width = comp.getPreferredSize().width;

    // get preferred size of the long value (remeber max of the pref. size for header and long value)
    comp = table.getDefaultRenderer(table.getModel().getColumnClass(index)).getTableCellRendererComponent(
            table, longValue, false, false, 0, index);
    width = Math.max(width, comp.getPreferredSize().width) + 2 * padding;

    // set preferred width of the column
    column.setPreferredWidth(width);
    // if the column contains boolean values, the preferred width
    // should also be its max width
    if (longValue instanceof Boolean) {
        column.setMaxWidth(width);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:UIUtilities.java

示例2: packColumn

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
private static void packColumn(JTable table, int vColIndex, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.
            getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width;            // Obtém a largura do cabeçalho da coluna
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
        renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp = renderer.getTableCellRendererComponent(
            table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;            // Obtém a largura maxima da coluna de dados
    for (int r = 0; r < table.getRowCount(); r++) {
        renderer = table.getCellRenderer(r, vColIndex);
        comp = renderer.getTableCellRendererComponent(
                table, table.getValueAt(r, vColIndex), false, false, r,
                vColIndex);
        width = Math.max(width, comp.getPreferredSize().width);
    }
    width += 2 * margin;            // Configura a largura
    col.setPreferredWidth(width);
}
 
开发者ID:karlos7,项目名称:ViolenciaContraMulher,代码行数:23,代码来源:FormataTamanhoColunasJTable.java

示例3: copyValues

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
public void copyValues(TableColumn base) {
	modelIndex = base.getModelIndex();
	identifier = base.getIdentifier();
	width = base.getWidth();
	minWidth = base.getMinWidth();
	setPreferredWidth(base.getPreferredWidth());
	maxWidth = base.getMaxWidth();
	headerRenderer = base.getHeaderRenderer();
	headerValue = base.getHeaderValue();
	cellRenderer = base.getCellRenderer();
	cellEditor = base.getCellEditor();
	isResizable = base.getResizable();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:14,代码来源:EditableTableHeaderColumn.java

示例4: paintCell

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
/**
 * Paints a header column cell.
 *
 * @param g           Graphics context
 * @param cellRect    The rectangle to contain the cell
 * @param columnIndex The header column to be painted
 */
private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) {
    TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    if (renderer == null) {
        renderer = header.getDefaultRenderer();
    }
    Component component = renderer.getTableCellRendererComponent(header
                    .getTable(), aColumn.getHeaderValue(), false, false, -1,
            columnIndex);
    rendererPane.add(component);
    rendererPane.paintComponent(g, component, header, cellRect.x,
            cellRect.y, cellRect.width, cellRect.height, true);
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:21,代码来源:GroupableTableHeaderUI.java

示例5: getHeaderHeight

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
/**
 * Calculate and return the height of the header.
 *
 * @return Header Height
 */
@SuppressWarnings("unchecked")
private int getHeaderHeight() {
    int height = 0;
    GroupableTableColumnModel columnModel = (GroupableTableColumnModel) header
            .getColumnModel();
    for (int column = 0; column < columnModel.getColumnCount(); column++) {
        TableColumn aColumn = columnModel.getColumn(column);
        TableCellRenderer renderer = aColumn.getHeaderRenderer();
        if (renderer == null) {
            renderer = header.getDefaultRenderer();
        }
        Component comp = renderer.getTableCellRendererComponent(header
                        .getTable(), aColumn.getHeaderValue(), false, false, -1,
                column);
        int cHeight = comp.getPreferredSize().height;
        Iterator iter = columnModel.getColumnGroups(aColumn);
        if (iter != null) {
            while (iter.hasNext()) {
                ColumnGroup cGroup = (ColumnGroup) iter.next();
                cHeight += cGroup.getSize(header.getTable()).height;
            }
        }
        height = Math.max(height, cHeight);
    }
    return height;
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:32,代码来源:GroupableTableHeaderUI.java

示例6: autoResizeColWidthNoFill

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
public static int autoResizeColWidthNoFill(JTable table) {
    int totalWidth = 0;
    int headerWidth = 0;

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    int margin = 5;
    for (int i = 0; i < table.getColumnCount(); i++) {
        int vColIndex = i;
        DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
        TableColumn col = colModel.getColumn(vColIndex);
        int width = 0;

        // Get width of column header
        TableCellRenderer renderer = col.getHeaderRenderer();

        if (renderer == null) {
            renderer = table.getTableHeader().getDefaultRenderer();
        }

        Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(),
                                                                false, false, 0, 0);

        width = comp.getPreferredSize().width;
        headerWidth = width;

        // Get maximum width of column data
        for (int r = 0; r < table.getRowCount(); r++) {
            renderer = table.getCellRenderer(r, vColIndex);
            comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex),
                                                          false, false, r, vColIndex);
            width = Math.max(width, comp.getPreferredSize().width);
        }

        // Add margin
        width += 2 * margin;

        width = Math.max(width, headerWidth + 20); // Make sure the width is wider than the
                                                   // header plus 20 to leave room for sorting
                                                   // arrows.

        // Set the width
        col.setPreferredWidth(width);

        totalWidth += width;
    }

    ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer())
            .setHorizontalAlignment(SwingConstants.LEFT);

    // table.setAutoCreateRowSorter(true);
    table.getTableHeader().setReorderingAllowed(false);

    return totalWidth;
}
 
开发者ID:Hitachi-Data-Systems,项目名称:Open-DM,代码行数:56,代码来源:GUIHelper.java


注:本文中的javax.swing.table.TableColumn.getHeaderRenderer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。