本文整理了Java中javax.swing.text.JTextComponent.scrollRectToVisible()
方法的一些代码示例,展示了JTextComponent.scrollRectToVisible()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.scrollRectToVisible()
方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:scrollRectToVisible
暂无
代码示例来源:origin: apache/pdfbox
private void scrollToWord(int offset)
{
try
{
textComponent.scrollRectToVisible(textComponent.modelToView(offset));
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
代码示例来源:origin: joel-costigliola/assertj-swing
@RunsInCurrentThread
private static void scrollToVisible(@Nonnull JTextComponent textBox, @Nonnull Rectangle r) {
textBox.scrollRectToVisible(r);
if (isVisible(textBox, r)) {
return;
}
scrollToVisibleIfIsTextField(textBox, r);
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-bugtracking
private void scrollToCurrent() {
try {
Rectangle r1 = currentComp.modelToView(currentStart);
Rectangle r2 = currentComp.modelToView(currentStart);
Rectangle r = r1.union(r2);
currentComp.scrollRectToVisible(r);
} catch (BadLocationException blex) {
BugtrackingManager.LOG.log(Level.INFO, blex.getMessage(), blex);
}
}
代码示例来源:origin: net.sf.squirrel-sql.plugins/graph
public void run()
{
_entryPanelManager.getEntryPanel().getTextComponent().scrollRectToVisible(new Rectangle(0,0));
_entryPanelManager.getEntryPanel().setCaretPosition(0);
}
};
代码示例来源:origin: nroduit/Weasis
public void showCurrentSearch(String pattern) {
if (!searchPostions.isEmpty() && StringUtil.hasText(pattern)) {
removeHighlights(textComponent);
try {
if (currentSearchIndex < 0 || currentSearchIndex >= searchPostions.size()) {
currentSearchIndex = 0;
}
int curPos = searchPostions.get(currentSearchIndex);
Highlighter hilite = textComponent.getHighlighter();
for (Integer pos : searchPostions) {
if (pos == curPos) {
hilite.addHighlight(pos, pos + pattern.length(), searchHighlightPainter);
} else {
hilite.addHighlight(pos, pos + pattern.length(), searchResultHighlightPainter);
}
}
textComponent.scrollRectToVisible(textComponent.modelToView(curPos));
} catch (BadLocationException e) {
LOGGER.error("Highight result of search", e); //$NON-NLS-1$
}
}
}
}
代码示例来源:origin: de.sciss/jsyntaxpane
@Override
public void windowDeactivated(WindowEvent e) {
target.getDocument().removeDocumentListener(QuickFindDialog.this);
Markers.removeMarkers(target, marker);
if (escaped) {
Rectangle aRect;
try {
aRect = target.modelToView(oldCaretPosition);
target.setCaretPosition(oldCaretPosition);
target.scrollRectToVisible(aRect);
} catch (BadLocationException ex) {
}
}
dispose();
}
};
代码示例来源:origin: nroduit/Weasis
if (!searchPostions.isEmpty()) {
try {
textComponent.scrollRectToVisible(textComponent.modelToView(searchPostions.get(0)));
textComponent.requestFocusInWindow();
} catch (BadLocationException e) {
代码示例来源:origin: com.jidesoft/jide-oss
private void scrollTextVisible(JTextComponent textComponent, int index, int length) {
// scroll highlight visible
if (index != -1) {
// Scroll the component if needed so that the composed text
// becomes visible.
try {
Rectangle begin = textComponent.modelToView(index);
if (begin == null) {
return;
}
Rectangle end = textComponent.modelToView(index + length);
if (end == null) {
return;
}
Rectangle bounds = _component.getVisibleRect();
if (begin.x <= bounds.width) { // make sure if scroll back to the beginning as long as selected rect is visible
begin.width = end.x;
begin.x = 0;
}
else {
begin.width = end.x - begin.x;
}
textComponent.scrollRectToVisible(begin);
}
catch (BadLocationException ble) {
}
}
}
代码示例来源:origin: antlr/stringtemplate4
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
代码示例来源:origin: org.antlr/ST4
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
代码示例来源:origin: jsevellec/cassandra-unit
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
代码示例来源:origin: antlr/antlr3
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
代码示例来源:origin: apache/servicemix-bundles
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
内容来源于网络,如有侵权,请联系作者删除!