当前位置: 首页>>代码示例>>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;未经允许,请勿转载。