本文整理匯總了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));
}