當前位置: 首頁>>代碼示例>>Java>>正文


Java JViewport.getViewRect方法代碼示例

本文整理匯總了Java中javax.swing.JViewport.getViewRect方法的典型用法代碼示例。如果您正苦於以下問題:Java JViewport.getViewRect方法的具體用法?Java JViewport.getViewRect怎麽用?Java JViewport.getViewRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JViewport的用法示例。


在下文中一共展示了JViewport.getViewRect方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: focusGained

import javax.swing.JViewport; //導入方法依賴的package包/類
@Override
public void focusGained(FocusEvent e) {
    if (e.isTemporary()) {
        return;
    }
    Component cmp = e.getComponent();
    if(cmp instanceof JComponent) {
        JViewport vp = getViewport(container);
        if(vp == null) {
            return;
        }
        Rectangle vr = vp.getViewRect();
        Point p = SwingUtilities.convertPoint(cmp.getParent(), cmp.getLocation(), container);
        final Rectangle r = new Rectangle(p, cmp.getSize());
        if(vr.intersects(r)) {
            return; 
        }
        container.scrollRectToVisible(r);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:UIUtils.java

示例2: actionPerformedImpl

import javax.swing.JViewport; //導入方法依賴的package包/類
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
	Container parent = textArea.getParent();
	if (parent instanceof JViewport) {
		JViewport viewport = (JViewport)parent;
		Point p = viewport.getViewPosition();
		p.y += delta*textArea.getLineHeight();
		if (p.y<0) {
			p.y = 0;
		}
		else {
			Rectangle viewRect = viewport.getViewRect();
			int visibleEnd = p.y + viewRect.height;
			if (visibleEnd>=textArea.getHeight()) {
				p.y = textArea.getHeight() - viewRect.height;
			}
		}
		viewport.setViewPosition(p);
	}
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:21,代碼來源:RTextAreaEditorKit.java

示例3: restoreScrollPosition

import javax.swing.JViewport; //導入方法依賴的package包/類
/**
 * Restore stored scroll position.
 */
private void restoreScrollPosition(boolean delayScrollWithMarkingDirtyRegion) {
    if (visibleTreePosition != null) {
        JTree tree = getJTree();
        if (tree != null) {
            int row = tree.getRowForPath(visibleTreePosition.getPath());
            if (row != -1) {
                Rectangle bounds = tree.getRowBounds(row);
                if (bounds != null) {
                    int scrollY = bounds.y - visibleTreePosition.getOffset();
                    JViewport viewport = mainScrollPane.getViewport();
                    Rectangle rect = viewport.getViewRect();
                    rect.y = scrollY;
                    if (!rect.isEmpty()) {
                        JComponent view = (JComponent) viewport.getView();
                        if (delayScrollWithMarkingDirtyRegion) {
                            RepaintManager.currentManager(viewport).addDirtyRegion(
                                    view,
                                    rect.x, rect.x, rect.width, rect.height);
                        }
                        ignoreScrollAdjustment = true;
                        try {
                            view.scrollRectToVisible(
                                    rect);
                        } finally {
                            ignoreScrollAdjustment = false;
                        }
                    }
                }
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:DebuggingViewComponent.java

示例4: preferredWidth

import javax.swing.JViewport; //導入方法依賴的package包/類
private int preferredWidth(ExtendedJTable table, int col) {
	TableColumn tableColumn = table.getColumnModel().getColumn(col);
	int width = (int) table.getTableHeader().getDefaultRenderer()
			.getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col).getPreferredSize()
			.getWidth();

	if (table.getRowCount() != 0) {
		int from = 0;
		int to = table.getRowCount();
		ExtendedJScrollPane scrollPane = (table).getExtendedScrollPane();
		if (scrollPane != null) {
			JViewport viewport = scrollPane.getViewport();
			Rectangle viewRect = viewport.getViewRect();
			from = table.rowAtPoint(new Point(0, viewRect.y));
			from = Math.max(0, from);
			to = table.rowAtPoint(new Point(0, viewRect.y + viewRect.height - 2));
			to = Math.min(to, table.getRowCount());
		}

		for (int row = from; row < to; 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);
		}
	}

	return width + table.getIntercellSpacing().width;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:30,代碼來源:ExtendedJTablePacker.java

示例5: mouseClicked

import javax.swing.JViewport; //導入方法依賴的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

示例6: packColumn

import javax.swing.JViewport; //導入方法依賴的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

示例7: moveLocation

import javax.swing.JViewport; //導入方法依賴的package包/類
/**
 * Moves the current location by a given amount.
 *
 * @param dr the number of rows by which to move the location
 * @param dc the number of columns by which to move the location
 */
public void moveLocation(int dr, int dc) {
    Location newLocation = new Location(currentLocation.getRow() + dr,
            currentLocation.getCol() + dc);
    if (!grid.isValid(newLocation))
        return;

    currentLocation = newLocation;

    JViewport viewPort = getEnclosingViewport();
    if (isPannableUnbounded()) {
        if (originRow > currentLocation.getRow())
            originRow = currentLocation.getRow();
        if (originCol > currentLocation.getCol())
            originCol = currentLocation.getCol();
        Dimension dim = viewPort.getSize();
        int rows = dim.height / (cellSize + 1);
        int cols = dim.width / (cellSize + 1);
        if (originRow + rows - 1 < currentLocation.getRow())
            originRow = currentLocation.getRow() - rows + 1;
        if (originCol + rows - 1 < currentLocation.getCol())
            originCol = currentLocation.getCol() - cols + 1;
    } else if (viewPort != null) {
        int dx = 0;
        int dy = 0;
        Point p = pointForLocation(currentLocation);
        Rectangle locRect = new Rectangle(p.x - cellSize / 2, p.y
                - cellSize / 2, cellSize + 1, cellSize + 1);

        Rectangle viewRect = viewPort.getViewRect();
        if (!viewRect.contains(locRect)) {
            while (locRect.x < viewRect.x + dx)
                dx -= cellSize + 1;
            while (locRect.y < viewRect.y + dy)
                dy -= cellSize + 1;
            while (locRect.getMaxX() > viewRect.getMaxX() + dx)
                dx += cellSize + 1;
            while (locRect.getMaxY() > viewRect.getMaxY() + dy)
                dy += cellSize + 1;

            Point pt = viewPort.getViewPosition();
            pt.x += dx;
            pt.y += dy;
            viewPort.setViewPosition(pt);
        }
    }
    repaint();
    showTip(getToolTipText(currentLocation),
            pointForLocation(currentLocation));
}
 
開發者ID:CBSkarmory,項目名稱:AWGW,代碼行數:56,代碼來源:GridPanel.java


注:本文中的javax.swing.JViewport.getViewRect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。