本文整理汇总了Java中javax.swing.text.JTextComponent.scrollRectToVisible方法的典型用法代码示例。如果您正苦于以下问题:Java JTextComponent.scrollRectToVisible方法的具体用法?Java JTextComponent.scrollRectToVisible怎么用?Java JTextComponent.scrollRectToVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.JTextComponent
的用法示例。
在下文中一共展示了JTextComponent.scrollRectToVisible方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
// Scroll the component down due to the extra visual space becomes visible.
Rectangle bounds = target.getBounds();
bounds.x = 0;
bounds.y = bounds.height;
bounds.width = 1;
bounds.height = 1;
target.scrollRectToVisible(bounds);
Caret caret = target.getCaret();
int dot = target.getDocument().getLength(); // end of document
boolean select = selectionEndAction.equals(getValue(Action.NAME));
if (select) {
caret.moveDot(dot);
} else {
caret.setDot(dot);
}
}
}
示例2: scrollToText
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
* Scrolls the specified text component so the text between the starting and ending index are visible.
*/
public static void scrollToText(JTextComponent textComponent, int startingIndex, int endingIndex) {
try {
Rectangle startingRectangle = textComponent.modelToView(startingIndex);
Rectangle endDingRectangle = textComponent.modelToView(endingIndex);
Rectangle totalBounds = startingRectangle.union(endDingRectangle);
textComponent.scrollRectToVisible(totalBounds);
textComponent.repaint();
} catch (BadLocationException e) {
e.printStackTrace();
}
}
示例3: ensureVisible
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
* Ensure that the given region will be visible in the view
* with the appropriate find insets.
*/
private void ensureVisible(JTextComponent c, int startOffset, int endOffset, Insets extraInsets) {
try {
Rectangle startBounds = c.modelToView(startOffset);
Rectangle endBounds = c.modelToView(endOffset);
if (startBounds != null && endBounds != null) {
startBounds.add(endBounds);
if (extraInsets != null) {
Rectangle visibleBounds = c.getVisibleRect();
int extraTop = (extraInsets.top < 0)
? -extraInsets.top * visibleBounds.height / 100 // percentage
: extraInsets.top * endBounds.height; // line count
startBounds.y -= extraTop;
startBounds.height += extraTop;
startBounds.height += (extraInsets.bottom < 0)
? -extraInsets.bottom * visibleBounds.height / 100 // percentage
: extraInsets.bottom * endBounds.height; // line count
int extraLeft = (extraInsets.left < 0)
? -extraInsets.left * visibleBounds.width / 100 // percentage
: extraInsets.left * endBounds.width; // char count
startBounds.x -= extraLeft;
startBounds.width += extraLeft;
startBounds.width += (extraInsets.right < 0)
? -extraInsets.right * visibleBounds.width / 100 // percentage
: extraInsets.right * endBounds.width; // char count
}
c.scrollRectToVisible(startBounds);
}
} catch (BadLocationException e) {
// do not scroll
}
}
示例4: actionPerformed
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
Caret caret = target.getCaret();
BaseDocument doc = (BaseDocument)target.getDocument();
try {
int dot = caret.getDot();
// #232675: if bounds are defined, use them rather than line start/end
Object o = target.getClientProperty(PROP_NAVIGATE_BOUNDARIES);
PositionRegion bounds = null;
int lineStartPos = Utilities.getRowStart(target, dot);
if (o instanceof PositionRegion) {
bounds = (PositionRegion)o;
int start = bounds.getStartOffset();
int end = bounds.getEndOffset();
int boundLineStart = Utilities.getRowStart(target, start);
// refinement: only use the boundaries if the caret is at the same line
// as boundary start; otherwise ignore the boundary and use document lines.
if (boundLineStart == lineStartPos && dot > start && dot <= end) {
// move to the region start
dot = start;
} else {
bounds = null;
}
}
if (bounds == null) {
if (homeKeyColumnOne) { // to first column
dot = lineStartPos;
} else { // either to line start or text start
int textStartPos = Utilities.getRowFirstNonWhite(doc, lineStartPos);
if (textStartPos < 0) { // no text on the line
textStartPos = Utilities.getRowEnd(target, lineStartPos);
}
if (dot == lineStartPos) { // go to the text start pos
dot = textStartPos;
} else if (dot <= textStartPos) {
dot = lineStartPos;
} else {
dot = textStartPos;
}
}
}
// For partial view hierarchy check bounds
dot = Math.max(dot, target.getUI().getRootView(target).getStartOffset());
String actionName = (String) getValue(Action.NAME);
boolean select = selectionBeginLineAction.equals(actionName)
|| selectionLineFirstColumnAction.equals(actionName);
// If possible scroll the view to its begining horizontally
// to ease user's orientation in the code.
Rectangle r = target.modelToView(dot);
Rectangle visRect = target.getVisibleRect();
if (r.getMaxX() < visRect.getWidth()) {
r.x = 0;
target.scrollRectToVisible(r);
}
target.putClientProperty("navigational.action", SwingConstants.WEST);
if (select) {
caret.moveDot(dot);
} else {
caret.setDot(dot);
}
} catch (BadLocationException e) {
target.getToolkit().beep();
}
}
}