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


Java JTableHeader.setResizingColumn方法代码示例

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


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

示例1: FitTableColumns

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
public static void FitTableColumns(JTable myTable){
	  JTableHeader header = myTable.getTableHeader();
	     int rowCount = myTable.getRowCount();
	     Enumeration columns = myTable.getColumnModel().getColumns();
	     while(columns.hasMoreElements()){
	         TableColumn column = (TableColumn)columns.nextElement();
	         int col = header.getColumnModel().getColumnIndex(column.getIdentifier());
	         int width = (int)myTable.getTableHeader().getDefaultRenderer()
	                 .getTableCellRendererComponent(myTable, column.getIdentifier()
	                         , false, false, -1, col).getPreferredSize().getWidth();
	         for(int row = 0; row<rowCount; row++){
	             int preferedWidth = (int)myTable.getCellRenderer(row, col).getTableCellRendererComponent(myTable,
	               myTable.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
	             width = Math.max(width, preferedWidth);
	         }
	         header.setResizingColumn(column); // ���к���Ҫ
	         column.setWidth(width+myTable.getIntercellSpacing().width);
	     }
}
 
开发者ID:sivanWu0222,项目名称:SimpleERP,代码行数:20,代码来源:QueryPortBelongs.java

示例2: setColumnWidth

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
final public int setColumnWidth(int intPcolumnIndex, int intPwidth) {
	final int intLidentifier = this.getColumnIdentifier(intPcolumnIndex);
	final JTableHeader objLjTableHeader = this.getTableHeader();
	final TableColumn objLtableColumn = this.getColumnModel().getColumn(intPcolumnIndex);
	objLjTableHeader.setResizingColumn(objLtableColumn);
	final int intLwidth =
							intPwidth == Constants.bytS_UNCLASS_NO_VALUE
																		? intLidentifier == Constants.bytS_UNCLASS_NO_VALUE
																															? Constants.bytS_UNCLASS_NO_VALUE
																															: this.intGidentifierColumnWidthA[intLidentifier]
																		: intPwidth;
	if (intLwidth != Constants.bytS_UNCLASS_NO_VALUE) {
		if (intLidentifier != Constants.bytS_UNCLASS_NO_VALUE) {
			this.intGidentifierColumnWidthA[intLidentifier] = intLwidth;
		}
		objLtableColumn.setWidth(intLwidth);
	}
	return intLwidth;
}
 
开发者ID:jugglemaster,项目名称:JuggleMasterPro,代码行数:20,代码来源:DataJTable.java

示例3: unpack

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
public void unpack() {
	JTableHeader header = getTableHeader();
	if (header != null) {
		for (int c = 0; c < getColumnCount(); c++) {
			TableColumn tableColumn = header.getColumnModel().getColumn(c);
			header.setResizingColumn(tableColumn); // this line is very important

			int width = DEFAULT_COLUMN_WIDTH;
			if (getWidth() / width > getColumnCount()) {
				width = getWidth() / getColumnCount();
			}
			tableColumn.setWidth(width);
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:16,代码来源:ExtendedJTable.java

示例4: fitTableColumns

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
public static void fitTableColumns(JTable myTable) {

        JTableHeader header = myTable.getTableHeader();
        int rowCount = myTable.getRowCount();
        Enumeration columns = myTable.getColumnModel().getColumns();
        while (columns.hasMoreElements()) {
            TableColumn column = (TableColumn) columns.nextElement();
            int col = header.getColumnModel().getColumnIndex(
                    column.getIdentifier());
            int width = (int) myTable
                    .getTableHeader()
                    .getDefaultRenderer()
                    .getTableCellRendererComponent(myTable,
                            column.getIdentifier(), false, false, -1, col)
                    .getPreferredSize().getWidth();
            for (int row = 0; row < rowCount; row++) {
                int preferedWidth = (int) myTable
                        .getCellRenderer(row, col)
                        .getTableCellRendererComponent(myTable,
                                myTable.getValueAt(row, col), false, false,
                                row, col).getPreferredSize().getWidth();
                width = Math.max(width, preferedWidth);
            }
            header.setResizingColumn(column); // 此行很重要
            column.setWidth(width + myTable.getIntercellSpacing().width + 4);// 使表格看起来不是那么拥挤,起到间隔作用
        }
    }
 
开发者ID:Harlber,项目名称:Method_Trace_Tool,代码行数:28,代码来源:Utils.java

示例5: resize

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
/**
 * Forces the table to resize given column.
 */
private void resize(int newWidth, JTable table) {
    int oldWidth = getWidth();
    JTableHeader header = table.getTableHeader();
    if (header == null) {
        return;
    }
    header.setResizingColumn(this);
    final int oldMin = getMinWidth();
    final int oldMax = getMaxWidth();
    setMinWidth(newWidth);
    setMaxWidth(newWidth);
    setWidth(newWidth);
    // The trick is to restore the original values
    // after the table has be layouted. During layout this column
    // has fixed width (by setting min==max==preffered)
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            setMinWidth(oldMin);
            setMaxWidth(oldMax);
        }
    });
    Container container;
    if ((header.getParent() == null) ||
            ((container = header.getParent().getParent()) == null) ||
            !(container instanceof JScrollPane)) {
        header.setResizingColumn(null);
        return;
    }
    
    if (!container.getComponentOrientation().isLeftToRight() &&
            ! header.getComponentOrientation().isLeftToRight()) {
        if (table != null) {
            JViewport viewport = ((JScrollPane)container).getViewport();
            int viewportWidth = viewport.getWidth();
            int diff = newWidth - oldWidth;
            int newHeaderWidth = table.getWidth() + diff;
            
            /* Resize a table */
            Dimension tableSize = table.getSize();
            tableSize.width += diff;
            table.setSize(tableSize);
            
            /* If this table is in AUTO_RESIZE_OFF mode and
             * has a horizontal scrollbar, we need to update
             * a view's position.
             */
            if ((newHeaderWidth >= viewportWidth) &&
                    (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                Point p = viewport.getViewPosition();
                p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                viewport.setViewPosition(p);
            }
        }
    }
    header.setResizingColumn(null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:61,代码来源:ETableColumn.java

示例6: mouseClicked

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
	if (e.getClickCount() == 2) {
		JTableHeader header = (JTableHeader) e.getSource();
		TableColumn tableColumn = getResizingColumn(header, e.getPoint());

		if (tableColumn == null) {
			return;
		}

		JTable table = header.getTable();

		if ((e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
			if (table instanceof ExtendedJTable) {
				((ExtendedJTable) table).pack();
				e.consume();
			}
		} else {
			int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
			int width = (int) header.getDefaultRenderer()
					.getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col)
					.getPreferredSize().getWidth();

			int firstRow = 0;
			int lastRow = table.getRowCount();

			if (table instanceof ExtendedJTable) {
				ExtendedJScrollPane scrollPane = ((ExtendedJTable) table).getExtendedScrollPane();
				if (scrollPane != null) {
					JViewport viewport = scrollPane.getViewport();
					Rectangle viewRect = viewport.getViewRect();
					if (viewport.getHeight() < table.getHeight()) {
						firstRow = table.rowAtPoint(new Point(0, viewRect.y));
						firstRow = Math.max(0, firstRow);
						lastRow = table.rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1));
						lastRow = Math.min(lastRow, table.getRowCount());
					}
				}
			}

			for (int row = firstRow; row < lastRow; row++) {
				int preferedWidth = (int) table.getCellRenderer(row, col)
						.getTableCellRendererComponent(table, table.getValueAt(row, col), false, false, row, col)
						.getPreferredSize().getWidth();
				width = Math.max(width, preferedWidth);
			}
			header.setResizingColumn(tableColumn); // this line is very important
			tableColumn.setWidth(width + table.getIntercellSpacing().width);

			e.consume();
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:54,代码来源:ExtendedJTableColumnFitMouseListener.java

示例7: packColumn

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
public void packColumn() {
	JTableHeader header = getTableHeader();
	if (header != null) {
		int col = getSelectedColumn();
		if (col >= 0) {
			TableColumn tableColumn = header.getColumnModel().getColumn(col);

			if (tableColumn != null) {
				int width = (int) header.getDefaultRenderer()
						.getTableCellRendererComponent(this, tableColumn.getIdentifier(), false, false, -1, col)
						.getPreferredSize().getWidth();

				int firstRow = 0;
				int lastRow = getRowCount();

				ExtendedJScrollPane scrollPane = getExtendedScrollPane();
				if (scrollPane != null) {
					JViewport viewport = scrollPane.getViewport();
					Rectangle viewRect = viewport.getViewRect();
					if (viewport.getHeight() < getHeight()) {
						firstRow = rowAtPoint(new Point(0, viewRect.y));
						firstRow = Math.max(0, firstRow);
						lastRow = rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1));
						lastRow = Math.min(lastRow, getRowCount());
					}
				}

				for (int row = firstRow; row < lastRow; row++) {
					int preferedWidth = (int) getCellRenderer(row, col)
							.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col)
							.getPreferredSize().getWidth();
					width = Math.max(width, preferedWidth);
				}

				header.setResizingColumn(tableColumn); // this line is very important

				tableColumn.setWidth(width + getIntercellSpacing().width);
			}
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:42,代码来源:ExtendedJTable.java


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