本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}
}
}
}
}
}
}
示例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;
}
示例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();
}
}
}
示例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);
}
}
}
}
示例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));
}