當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。