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


Java TableColumn.getPreferredWidth方法代码示例

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


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

示例1: getPreferredScrollableViewportSize

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
@Override
public Dimension getPreferredScrollableViewportSize() {
    if( needCalcRowHeight ) {
        calcRowHeight( getOffscreenGraphics() );
        prefSize = null;
    }
    if( null == prefSize ) {
        Dimension dim = new Dimension();
        for( int i=0; i<getColumnCount(); i++ ) {
            TableColumn tc = getColumnModel().getColumn( i );
            dim.width += tc.getPreferredWidth();
        }
        int rowCount = Math.min( MAX_VISIBLE_ROWS, getRowCount() );
        dim.height = rowCount*getRowHeight();
        Rectangle screen = Utilities.getUsableScreenBounds();
        dim.width = Math.min( dim.width, screen.width-100 );
        dim.height = Math.min( dim.height, screen.height-100 );
        prefSize = dim;
    }
    return prefSize;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:Table.java

示例2: updateTableColumnSizes

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
private void updateTableColumnSizes() {
    ETable table = tableView.getTable();
    Font font = tableView.getFont();
    FontMetrics fm = tableView.getFontMetrics(font);
    int maxCharWidth = fm.charWidth('A');
    int editingBorder = 4;
    TableColumnModel columnModel = table.getColumnModel();

    TableColumn nameColumn = columnModel.getColumn(0);
    nameColumn.setPreferredWidth(8 * maxCharWidth + editingBorder); // 8 chars for name

    TableColumn keyColumn = columnModel.getColumn(1);
    // Single char for key (but 3 chars to prevent "..." in column header)
    keyColumn.setPreferredWidth(3 * maxCharWidth + editingBorder);
    keyColumn.setMinWidth(keyColumn.getPreferredWidth());

    TableColumn locationColumn = columnModel.getColumn(2);
    Insets insets = tableView.getBorder().getBorderInsets(tableView);
    int remainingWidth = tableView.getParent().getWidth() - insets.left - insets.right;
    remainingWidth -= 2 * columnModel.getColumnMargin();
    remainingWidth -= nameColumn.getPreferredWidth();
    remainingWidth -= keyColumn.getPreferredWidth();
    locationColumn.setPreferredWidth(remainingWidth); // remaining space for location
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:BookmarksView.java

示例3: autoResizeColWidth

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
public static JTable autoResizeColWidth(JTable table, int extraSpaceToColumn) {
    if (extraSpaceToColumn < 0 || extraSpaceToColumn >= table.getColumnCount()) {
        throw new IllegalArgumentException("Illegal Column index.  Table " + table.getName()
                + " has " + table.getColumnCount()
                + " columns.  Can't set extra space to column " + extraSpaceToColumn);
    }

    int totalWidth = autoResizeColWidthNoFill(table);

    int availableWidth = table.getParent().getWidth();

    if (totalWidth >= availableWidth) {
        return table;
    }
    int increaseBy = availableWidth - totalWidth;

    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(extraSpaceToColumn);
    int oldWidth = col.getPreferredWidth();
    col.setPreferredWidth(oldWidth + increaseBy);

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

示例4: DataTable

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
public DataTable(TableModel model) {
    super(model);
    setSurrendersFocusOnKeystroke(true);
    TableColumnModel cmodel = getColumnModel();
    int i;
    int ccount = model.getColumnCount();
    int columnWidth;
    int preferredWidth;
    String columnName;
    int width = 0;
    for (i = 0; i < ccount; i++) {
        TableColumn col = cmodel.getColumn(i);
        Map cmap = ColumnItem.getColumnProperty(i);
        col.setIdentifier(cmap.get("name")); //NOI18N
        columnName = NbBundle.getMessage (CreateTableDialog.class, "CreateTable_" + i); //NOI18N
        columnWidth = (new Double(getFontMetrics(getFont()).getStringBounds(columnName, getGraphics()).getWidth())).intValue() + 20;
        if (cmap.containsKey("width")) { // NOI18N
            if (((Integer)cmap.get("width")).intValue() < columnWidth)
                col.setPreferredWidth(columnWidth);
            else
                col.setPreferredWidth(((Integer)cmap.get("width")).intValue()); // NOI18N
            preferredWidth = col.getPreferredWidth();
        }
        if (cmap.containsKey("minwidth")) // NOI18N
            if (((Integer)cmap.get("minwidth")).intValue() < columnWidth)
                col.setMinWidth(columnWidth);
            else
                col.setMinWidth(((Integer)cmap.get("minwidth")).intValue()); // NOI18N
        //				if (cmap.containsKey("alignment")) {}
        //				if (cmap.containsKey("tip")) ((JComponent)col.getCellRenderer()).setToolTipText((String)cmap.get("tip"));
        if (i < 7) { // the first 7 columns should be visible
            width += col.getPreferredWidth();
        }
    }
    width = Math.min(Math.max(width, 380), Toolkit.getDefaultToolkit().getScreenSize().width - 100);
    setPreferredScrollableViewportSize(new Dimension(width, 150));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:CreateTableDialog.java

示例5: getPreferredSize

import javax.swing.table.TableColumn; //导入方法依赖的package包/类
/**
 * Invokes the getPreferredSize method on each UI handled by this object.
 *
 * @param c the component whose preferred size is being queried; this
 *          argument is ignored.
 * @return the dimension of the whole header
 */
@SuppressWarnings("unchecked")
public Dimension getPreferredSize(JComponent c) {
    long width = 0;
    Enumeration columns = header.getColumnModel().getColumns();
    while (columns.hasMoreElements()) {
        TableColumn aColumn = (TableColumn) columns.nextElement();
        width = width + aColumn.getPreferredWidth();
    }
    return createHeaderSize(width);
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:18,代码来源:GroupableTableHeaderUI.java


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