本文整理了Java中javax.swing.text.JTextComponent.setSelectionEnd()
方法的一些代码示例,展示了JTextComponent.setSelectionEnd()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.setSelectionEnd()
方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:setSelectionEnd
暂无
代码示例来源:origin: nativelibs4java/JNAerator
@Override
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
jtc.setSelectionStart(0);
jtc.setSelectionEnd(0);
}
});
代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl
public void run() {
tc.setText(lastSuggestion);
tc.setSelectionEnd(lastSuggestion.length());
tc.setSelectionStart(caretLocation);
suggestingContent = false;
}
});
代码示例来源:origin: org.protege/protege-editor-owl
public void run() {
tc.setText(lastSuggestion);
tc.setSelectionEnd(lastSuggestion.length());
tc.setSelectionStart(caretLocation);
suggestingContent = false;
}
});
代码示例来源:origin: sdedit/sdedit
public void run() {
textArea.setSelectionStart(wordBegin);
textArea.setSelectionEnd(wordEnd);
textArea.replaceSelection(suggestion);
wordEnd = wordBegin + suggestion.length();
}
});
代码示例来源:origin: org.codehaus.mevenide/nb-project
private void setTextFieldValue(String value, String projectValue, JTextComponent field) {
if (value != null) {
field.setText(value);
component.setToolTipText(""); //NOI18N
inherited = false;
label.setFont(label.getFont().deriveFont(Font.BOLD));
} else if (projectValue != null) {
field.setText(projectValue);
field.setSelectionEnd(projectValue.length());
field.setSelectionStart(0);
// field.setBackground(INHERITED);
label.setFont(label.getFont().deriveFont(Font.PLAIN));
component.setToolTipText(NbBundle.getMessage(TextComponentUpdater.class, "MSG_Value_Inherited"));
inherited = true;
} else {
field.setText("");//NOI18N
component.setToolTipText("");//NOI18N
inherited = false;
label.setFont(label.getFont().deriveFont(Font.BOLD));
}
}
代码示例来源:origin: protegeproject/protege
private void handleDocumentUpdated() {
if (!suggestingContent){
final Document doc = tc.getDocument();
caretLocation = tc.getCaretPosition()+1;
final int docLength = doc.getLength();
if (docLength == caretLocation){
try {
String currentText = doc.getText(0, doc.getLength());
lastSuggestion = suggestContent(currentText.substring(0, caretLocation));
if (lastSuggestion != null){
suggestingContent = true;
SwingUtilities.invokeLater(() -> {
tc.setText(lastSuggestion);
tc.setSelectionEnd(lastSuggestion.length());
tc.setSelectionStart(caretLocation);
suggestingContent = false;
});
}
}
catch (BadLocationException ex) {
throw new RuntimeException(ex);
}
}
}
}
代码示例来源:origin: edu.stanford.protege/ca.uvic.cs.chisel.cajun
private void highlightCompletedText(int start) {
editor.setSelectionStart(start);
editor.setSelectionEnd(getLength());
}
代码示例来源:origin: mucommander/mucommander
/**
* Overrides JPanel#requestFocus() method to request focus on the first component
* and select its contents if it is an instance of JTextComponent.
*/
@Override
public void requestFocus() {
if(firstComponent ==null)
super.requestFocus();
else {
if(firstComponent instanceof JTextComponent) {
JTextComponent textComponent = (JTextComponent) firstComponent;
String text = textComponent.getText();
if(!text.equals("")) {
textComponent.setSelectionStart(0);
textComponent.setSelectionEnd(text.length());
}
}
firstComponent.requestFocus();
}
}
}
代码示例来源:origin: org.gosu-lang.gosu/gosu-editor
public static void replaceWordAtCaretDynamicAndRemoveEmptyParens( JTextComponent editor, String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg )
{
try
{
int caret = editor.getCaretPosition();
if( editor.getDocument().getLength() >= caret + 2 && editor.getText( caret, 2 ).equals( "()" ) )
{
editor.setSelectionStart( caret );
editor.setSelectionEnd( caret + 2 );
editor.replaceSelection( "" );
}
}
catch( BadLocationException e )
{
// ignore
}
replaceWordAtCaretDynamic( editor, strText, replaceWordCallback, selectFirstArg );
}
代码示例来源:origin: org.gosu-lang.gosu/gosu-lab
public static void replaceWordAtCaretDynamicAndRemoveEmptyParens( JTextComponent editor, String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord )
{
performCompoundUndableEdit( editor, () -> {
try
{
int caret = editor.getCaretPosition();
if( editor.getDocument().getLength() >= caret + 2 && editor.getText( caret, 2 ).equals( "()" ) )
{
editor.setSelectionStart( caret );
editor.setSelectionEnd( caret + 2 );
editor.replaceSelection( "" );
}
}
catch( BadLocationException e )
{
// ignore
}
replaceWordAtCaretDynamic( editor, strText, replaceWordCallback, selectFirstArg, replaceWholeWord );
} );
}
代码示例来源:origin: chatty/chatty
private void fix(DocumentEvent e) {
int start = c.getSelectionStart();
int end = c.getSelectionEnd();
if (start != end && start > e.getOffset()) {
if (e.getType() == DocumentEvent.EventType.INSERT) {
c.setSelectionStart(start + e.getLength());
c.setSelectionEnd(end + e.getLength());
} else if (e.getType() == DocumentEvent.EventType.REMOVE) {
c.setSelectionStart(start - e.getLength());
c.setSelectionEnd(end - e.getLength());
}
}
}
代码示例来源:origin: org.activecomponents.jadex/jadex-commons-gui
/**
*
*/
private void clearSelection()
{
// Save caret position since selections moves the caret.
int pos = getEditorComponent().getCaretPosition();
int i = getText().length();
getEditorComponent().setSelectionStart(i);
getEditorComponent().setSelectionEnd(i);
getEditorComponent().setCaretPosition(pos);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
private void prepareEditor() {
Component c = getEditor().getEditorComponent();
if (c instanceof JTextComponent) {
JTextComponent jtc = (JTextComponent) c;
String s = jtc.getText();
if (s != null && s.length() > 0){
jtc.setSelectionStart(0);
jtc.setSelectionEnd(s.length());
}
if (tableUI) {
jtc.setBackground(getBackground());
} else {
jtc.setBackground(PropUtils.getTextFieldBackground());
}
}
if (getLayout() != null) {
getLayout().layoutContainer(this);
}
repaint();
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
private void prepareEditor() {
Component c = getEditor().getEditorComponent();
if (c instanceof JTextComponent) {
JTextComponent jtc = (JTextComponent) c;
String s = jtc.getText();
if (s != null && s.length() > 0){
jtc.setSelectionStart(0);
jtc.setSelectionEnd(s.length());
}
if (tableUI) {
jtc.setBackground(getBackground());
} else {
jtc.setBackground(PropUtils.getTextFieldBackground());
}
}
if (getLayout() != null) {
getLayout().layoutContainer(this);
}
repaint();
}
代码示例来源:origin: org.netbeans.api/org-openide-explorer
private void prepareEditor() {
Component c = getEditor().getEditorComponent();
if (c instanceof JTextComponent) {
JTextComponent jtc = (JTextComponent) c;
String s = jtc.getText();
if ((s != null) && (s.length() > 0)) {
jtc.setSelectionStart(0);
jtc.setSelectionEnd(s.length());
}
if (tableUI) {
jtc.setBackground(getBackground());
} else {
jtc.setBackground(PropUtils.getTextFieldBackground());
}
if( tableUI )
jtc.requestFocus();
}
if (getLayout() != null) {
getLayout().layoutContainer(this);
}
repaint();
}
代码示例来源:origin: org.jclarion/clarion-runtime
@Override
protected void handleAWTChange(int indx, ClarionObject value) {
if (indx==Prop.TOUCHED) {
modified=value.boolValue();
return;
}
if (indx == Prop.SELSTART) {
JTextComponent f = field;
if (f!=null) {
f.setSelectionStart(value.intValue() - 1);
}
return;
}
if (indx == Prop.SELEND) {
JTextComponent f = field;
if (f!=null) {
f.setSelectionEnd(value.intValue());
}
return;
}
super.handleAWTChange(indx, value);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor
public void run() {
try {
final BaseDocument doc = (BaseDocument)txt.getDocument();
final int s = Utilities.getRowStartFromLineOffset(doc, getSelectionStartLine(txt) - 1);
final int e = Utilities.getRowEnd(txt, Utilities.getRowStartFromLineOffset(doc, getSelectionEndLine(txt) - 1));
doc.insertString(e, "\n//#enddebug", null); //NOI18N
doc.insertString(s, "//#mdebug\n", null); //NOI18N
txt.setSelectionEnd(txt.getSelectionStart());
} catch (BadLocationException ble) {
ErrorManager.getDefault().notify(ble);
}
RecommentAction.actionPerformed(txt);
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor
public void run() {
try {
if (b.getType() == PPLine.ELSE) {
//insert new block before else
final int offs = Utilities.getRowStartFromLineOffset(doc, b.getStartLine() - 1);
doc.insertString(offs, "//#elif \n" + text + "\n", null); //NOI18N
txt.setSelectionStart(offs + 8);
txt.setSelectionEnd(offs + 8);
} else {
//insert new block after the current
final int offs = Utilities.getRowEnd(txt, Utilities.getRowStartFromLineOffset(doc, b.getEndLine() - (b.hasFooter() ? 2 : 1)));
doc.insertString(offs, "\n//#elif \n" + text, null); //NOI18N
txt.setSelectionStart(offs + 9);
txt.setSelectionEnd(offs + 9);
}
} catch (BadLocationException ble) {
ErrorManager.getDefault().notify(ble);
}
RecommentAction.actionPerformed(txt);
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf
target.setSelectionEnd(to + diff);
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor
public void run() {
try {
final BaseDocument doc = (BaseDocument)txt.getDocument();
final int s = Utilities.getRowStartFromLineOffset(doc, getSelectionStartLine(txt) - 1);
final int e = Utilities.getRowEnd(txt, Utilities.getRowStartFromLineOffset(doc, getSelectionEndLine(txt) - 1));
final String text = doc.getText(s, e-s);
doc.insertString(e, "\n//#else\n" + text + "\n//#endif", null); //NOI18N
doc.insertString(s, "//#if \n", null); //NOI18N
txt.setSelectionStart(s + 6);
txt.setSelectionEnd(s + 6);
} catch (BadLocationException ble) {
ErrorManager.getDefault().notify(ble);
}
RecommentAction.actionPerformed(txt);
}
});
内容来源于网络,如有侵权,请联系作者删除!