@Override public void focusLost(FocusEvent arg0) { // TODO Auto-generated method stub jtc.setSelectionStart(0); jtc.setSelectionEnd(0); } });
public void run() { tc.setText(lastSuggestion); tc.setSelectionEnd(lastSuggestion.length()); tc.setSelectionStart(caretLocation); suggestingContent = false; } });
public void run() { tc.setText(lastSuggestion); tc.setSelectionEnd(lastSuggestion.length()); tc.setSelectionStart(caretLocation); suggestingContent = false; } });
public void run() { textArea.setSelectionStart(wordBegin); textArea.setSelectionEnd(wordEnd); textArea.replaceSelection(suggestion); wordEnd = wordBegin + suggestion.length(); } });
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)); } }
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); } } } }
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); } } } }
private void highlightCompletedText(int start) { editor.setSelectionStart(start); editor.setSelectionEnd(getLength()); }
/** * 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(); } } }
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 ); }
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 ); } ); }
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()); } } }
/** * */ 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); }
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(); }
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(); }
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(); }
@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); }
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); } });
target.setSelectionStart(from); target.setSelectionEnd(to + diff);
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); } });