本文整理汇总了Java中javax.swing.JViewport.setViewPosition方法的典型用法代码示例。如果您正苦于以下问题:Java JViewport.setViewPosition方法的具体用法?Java JViewport.setViewPosition怎么用?Java JViewport.setViewPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JViewport
的用法示例。
在下文中一共展示了JViewport.setViewPosition方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changed
import javax.swing.JViewport; //导入方法依赖的package包/类
private void changed() {
JViewport viewport = sp.getViewport();
Point viewPosition = viewport.getViewPosition();
if (viewPosition.x > 0) {
try {
Rectangle textRect = editorPane.getUI().modelToView(editorPane, editorPane.getDocument().getLength());
int textLength = textRect.x + textRect.width;
int viewLength = viewport.getExtentSize().width;
//System.out.println("Utilities.createSingleLineEditor(): spLength = "+sp.getSize().width+", viewLength = "+viewLength+", textLength = "+textLength+", viewPosition = "+viewPosition);
if (textLength < (viewPosition.x + viewLength)) {
viewPosition.x = Math.max(textLength - viewLength, 0);
viewport.setViewPosition(viewPosition);
//System.out.println("Utilities.createSingleLineEditor(): setting new view position = "+viewPosition);
}
} catch (BadLocationException blex) {
Exceptions.printStackTrace(blex);
}
}
}
示例2: autoscroll
import javax.swing.JViewport; //导入方法依赖的package包/类
/** notify the Component to autoscroll */
public void autoscroll(Point cursorLoc) {
JViewport viewport = getViewport();
Point viewPos = viewport.getViewPosition();
int viewHeight = viewport.getExtentSize().height;
if ((cursorLoc.y - viewPos.y) <= realInsets.top) {
// scroll up
viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - realInsets.top, 0)));
} else if (((viewPos.y + viewHeight) - cursorLoc.y) <= realInsets.bottom) {
// scroll down
viewport.setViewPosition(
new Point(viewPos.x, Math.min(viewPos.y + realInsets.bottom, this.getHeight() - viewHeight))
);
}
}
示例3: 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);
}
}
示例4: setGrid
import javax.swing.JViewport; //导入方法依赖的package包/类
/**
* Sets the grid being displayed. Reset the cellSize to be the
* largest that fits the entire grid in the current visible area (use
* default if grid is too large).
*
* @param gr the grid to display
*/
public void setGrid(Grid<?> gr) {
currentLocation = new Location(0, 0);
JViewport vp = getEnclosingViewport(); // before changing, reset
// scroll/pan position
if (vp != null)
vp.setViewPosition(new Point(0, 0));
grid = gr;
originRow = originCol = 0;
if (grid.getNumRows() == -1 && grid.getNumCols() == -1) {
numRows = numCols = 2000;
// This determines the "virtual" size of the pan world
} else {
numRows = grid.getNumRows();
numCols = grid.getNumCols();
}
recalculateCellSize(MIN_CELL_SIZE);
}
示例5: setExtentPosition
import javax.swing.JViewport; //导入方法依赖的package包/类
void setExtentPosition(int x, int y) {
JViewport port = getParentViewport();
if (port != null) {
Point p = new Point(Math.max(x, 0), Math.max(y, 0));
port.setViewPosition(p);
}
}
示例6: autoscroll
import javax.swing.JViewport; //导入方法依赖的package包/类
/** Performs autoscroll operation.
*/
public void autoscroll(Point cursorLoc) {
JViewport viewport = getViewport();
if (viewport == null) {
return;
}
Point viewPos = viewport.getViewPosition();
int viewHeight = viewport.getExtentSize().height;
int viewWidth = viewport.getExtentSize().width;
// perform scrolling
if ((cursorLoc.y - viewPos.y) < insets.top) {
// scroll up
viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - scrollUnits.top, 0)));
} else if (((viewPos.y + viewHeight) - cursorLoc.y) < insets.bottom) {
// scroll down
viewport.setViewPosition(
new Point(viewPos.x, Math.min(viewPos.y + scrollUnits.bottom, comp.getHeight() - viewHeight))
);
} else if ((cursorLoc.x - viewPos.x) < insets.left) {
// scroll left
viewport.setViewPosition(new Point(Math.max(viewPos.x - scrollUnits.left, 0), viewPos.y));
} else if (((viewPos.x + viewWidth) - cursorLoc.x) < insets.right) {
// scroll right
viewport.setViewPosition(
new Point(Math.min(viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth), viewPos.y)
);
}
}
示例7: scrollTo
import javax.swing.JViewport; //导入方法依赖的package包/类
private void scrollTo() {
//out("Scroll to: " + myPaperNumber);
Paper paper = myPapers.get(myPaperNumber - 1);
int gap = getGap();
int x = paper.getX() - gap;
int y = paper.getY() - gap;
int w = paper.getWidth();
int h = paper.getHeight();
JViewport view = myScrollPane.getViewport();
if ( !view.getViewRect().contains(x, y, w, h)) {
view.setViewPosition(new Point(x, y));
updatePaperPanel();
}
}
示例8: adjustTreeScrollBar
import javax.swing.JViewport; //导入方法依赖的package包/类
private void adjustTreeScrollBar(int treeViewWidth) {
DebugTreeView tView = getTreeView();
if (tView == null) {
scrollBarPanel.setVisible(false);
return;
}
JViewport viewport = tView.getViewport();
Point point = viewport.getViewPosition();
if (point.y < 0) {
viewport.setViewPosition(new Point(point.x, 0));
}
Dimension viewSize = viewport.getExtentSize();
Dimension treeSize = viewport.getViewSize();
if (treeViewWidth < 0) {
treeViewWidth = treeSize.width;
}
int unitHeight = tView.getUnitHeight();
if (unitHeight > 0) {
JScrollBar sbar = mainScrollPane.getVerticalScrollBar();
if (sbar.getUnitIncrement() != unitHeight) {
sbar.setUnitIncrement(unitHeight);
}
}
if (treeViewWidth <= viewSize.width) {
scrollBarPanel.setVisible(false);
} else {
treeScrollBar.setMaximum(treeViewWidth);
treeScrollBar.setVisibleAmount(viewSize.width);
if (unitHeight > 0) {
treeScrollBar.setUnitIncrement(unitHeight / 2);
}
treeScrollBar.setBlockIncrement(viewSize.width);
scrollBarPanel.setVisible(true);
} // else
}
示例9: adjustmentValueChanged
import javax.swing.JViewport; //导入方法依赖的package包/类
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
DebugTreeView tView = getTreeView();
if (tView == null) {
return;
}
JViewport viewport = tView.getViewport();
Point position = viewport.getViewPosition();
viewport.setViewPosition(new Point(e.getValue(), position.y));
}
示例10: AtualizaTamanho
import javax.swing.JViewport; //导入方法依赖的package包/类
public void AtualizaTamanho() {
int pos = alturaTexto;
if (pos > getHeight()) {
JViewport jvp = ((JViewport) getParent());
setSize(jvp.getExtentSize().width, pos + 2);
setPreferredSize(getSize());
if (alturaTexto > jvp.getHeight()) {
jvp.setViewPosition(new Point(espaco, getHeight()));
}
repaint();
}
}
示例11: recenter
import javax.swing.JViewport; //导入方法依赖的package包/类
/**
* Pans the display back to the origin, so that 0, 0 is at the the upper
* left of the visible viewport.
*/
public void recenter(Location loc) {
originRow = loc.getRow();
originCol = loc.getCol();
repaint();
JViewport vp = getEnclosingViewport();
if (vp != null) {
if (!isPannableUnbounded()
|| !(vp instanceof PseudoInfiniteViewport))
vp.setViewPosition(pointForLocation(loc));
else
showPanTip();
}
}
示例12: resize
import javax.swing.JViewport; //导入方法依赖的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);
}
示例13: updateTextInAWT
import javax.swing.JViewport; //导入方法依赖的package包/类
private void updateTextInAWT(EditorCookie es, final String in) throws IOException, BadLocationException {
StyledDocument tmpdoc = es.getDocument();
if (tmpdoc == null)
tmpdoc = es.openDocument();
//sample editor position
JEditorPane[] eps = es.getOpenedPanes();
JEditorPane pane = null;
JViewport port = null;
int caretPosition = 0;
Point viewPosition = null;
if (eps != null) {
pane = eps[0];
caretPosition = pane.getCaretPosition();
port = getParentViewport (pane);
if (port != null)
viewPosition = port.getViewPosition();
}
// prepare modification task
final Exception[] taskEx = new Exception[] {null};
final StyledDocument sdoc = tmpdoc;
Runnable task = new Runnable() {
public void run() {
try {
sdoc.remove (0, sdoc.getLength()); // right alternative
// we are at Unicode level
sdoc.insertString (0, in, null);
} catch (Exception iex) {
taskEx[0] = iex;
}
}
};
// perform document modification
org.openide.text.NbDocument.runAtomicAsUser(sdoc, task);
//??? setModified (true);
//restore editor position
if (eps != null) {
try {
pane.setCaretPosition (caretPosition);
} catch (IllegalArgumentException e) {
}
port.setViewPosition (viewPosition);
}
if (taskEx[0]!=null) {
if (taskEx[0] instanceof IOException) {
throw (IOException)taskEx[0];
}
throw new IOException(taskEx[0]);
}
}
示例14: 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));
}