本文整理了Java中javax.swing.text.JTextComponent.moveCaretPosition()
方法的一些代码示例,展示了JTextComponent.moveCaretPosition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.moveCaretPosition()
方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:moveCaretPosition
暂无
代码示例来源:origin: stackoverflow.com
JTextComponent editor = ((JTextField) myComboBox.getEditor().getEditorComponent());
editor.setCaretPosition(getLength());
editor.moveCaretPosition(0);
代码示例来源:origin: de.sciss/jsyntaxpane
@Override
public void actionPerformed(JTextComponent target, SyntaxDocument sDoc,
int dot, ActionEvent e) {
try {
target.moveCaretPosition(SmartHomeAction.getSmartHomeOffset(target, sDoc, dot));
} catch (BadLocationException ex) {
Logger.getLogger(SmartHomeSelectAction.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
代码示例来源:origin: de.sciss/syntaxpane
@Override
public void actionPerformed(JTextComponent target, SyntaxDocument sDoc,
int dot, ActionEvent e) {
try {
target.moveCaretPosition(SmartHomeAction.getSmartHomeOffset(target, sDoc, dot));
} catch (BadLocationException ex) {
Logger.getLogger(SmartHomeSelectAction.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
代码示例来源:origin: abbot/abbot
public void run() {
tc.setCaretPosition(0);
tc.moveCaretPosition(0);
}
});
代码示例来源:origin: bcdev/beam
@Override
public void focusGained(final FocusEvent e) {
final JTextComponent tc = ((JTextComponent) e.getComponent());
tc.setCaretPosition(tc.getText().length());
tc.moveCaretPosition(0);
}
};
代码示例来源:origin: joel-costigliola/assertj-swing
@RunsInCurrentThread
static void selectTextInRange(@Nonnull JTextComponent textBox, int start, int end) {
textBox.setCaretPosition(start);
textBox.moveCaretPosition(end);
}
代码示例来源:origin: net.sf.cuf/cuf-swing
private void highlightCompletedText(final int pStart)
{
mEditor.setCaretPosition(getLength());
mEditor.moveCaretPosition(pStart);
}
代码示例来源:origin: triplea-game/triplea
private void highlightCompletedText(final int start) {
editor.setCaretPosition(getLength());
editor.moveCaretPosition(start);
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
/**
* Marks/selects the text that is displayed inside the text component starting from the
* character with index <tt>start</tt>.
* @param start index of the first character that should be marked
*/
public void markText(int start) {
getTextComponent().setCaretPosition(getTextComponent().getText().length());
getTextComponent().moveCaretPosition(start);
}
}
代码示例来源:origin: com.jidesoft/jide-oss
private void highlightCompletedText(int start) {
int length = getTextComponent().getDocument().getLength();
getTextComponent().setCaretPosition(length);
if (start < 0) {
start = 0;
}
if (start > length) {
start = length;
}
getTextComponent().moveCaretPosition(start);
}
代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop
/**
* Marks/selects the text that is displayed inside the text component starting from the
* character with index <tt>start</tt>.
* @param start index of the first character that should be marked
*/
public void markText(int start) {
getTextComponent().setCaretPosition(getTextComponent().getText().length());
getTextComponent().moveCaretPosition(start);
}
}
代码示例来源:origin: tmyroadctfig/swingx
/**
* Marks/selects the text that is displayed inside the text component starting from the
* character with index <tt>start</tt>.
* @param start index of the first character that should be marked
*/
public void markText(int start) {
getTextComponent().setCaretPosition(getTextComponent().getText().length());
getTextComponent().moveCaretPosition(start);
}
}
代码示例来源:origin: cytoscape.coreplugins/quickfind
/**
* Highlights Completed Text, so that it is clear which text was entered
* by the user, and which text was auto-completed.
*
* @param start start index.
*/
private void highlightCompletedText(int start) {
debug("highlightCompletedText, start= " + start);
editor.setCaretPosition(getLength());
editor.moveCaretPosition(start);
}
代码示例来源:origin: igniterealtime/Spark
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException {
super.insertString(offs, str, a);
String word = autoComplete(getText(0, getLength()));
if (word != null) {
super.insertString(offs + str.length(), word, a);
comp.setCaretPosition(offs + str.length());
comp.moveCaretPosition(getLength());
}
}
代码示例来源: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/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: 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);
}
}
代码示例来源: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: org.gosu-lang.gosu/gosu-editor
protected void showValueCompletionPopup( IValuePopup popup, boolean bFocusInEditor )
{
getGosuEditor().setValuePopup( popup );
IParseTree currentLocation = getDeepestLocationToComplete();
if( currentLocation != null &&
currentLocation.getParsedElement() instanceof IExpression &&
shouldPositionAtStartOfElement( currentLocation, getEditor() ) )
{
// Highlight/select the location to be visually specific about what is being acted on.
getEditor().setCaretPosition( currentLocation.getOffset() );
getEditor().moveCaretPosition( currentLocation.getOffset() + currentLocation.getLength() );
}
getGosuEditor().displayValuePopup( getEditor().getSelectionStart(), bFocusInEditor );
}
内容来源于网络,如有侵权,请联系作者删除!