Document doc = textComponent.getDocument(); try { doc.remove(pos, find.length()); doc.insertString(pos, replace, attributeSet);
Document doc = textComponent.getDocument(); try { doc.remove(pos, find.length()); doc.insertString(pos, replace, attributeSet);
/** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { ExTextField target = (ExTextField)getTextComponent(e); target.saveLastEntry(); Document doc = target.getDocument(); Caret caret = target.getCaret(); try { doc.remove(caret.getDot(), doc.getLength()); } catch (BadLocationException ex) { // ignore } } }
doc.remove(insertIndex, 1); doc.insertString(insertIndex, charToInsert, null); input.select(insertIndex + 1, input.getSelectionEnd());
/** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { ExTextField target = (ExTextField)getTextComponent(e); target.saveLastEntry(); Document doc = target.getDocument(); Caret caret = target.getCaret(); try { doc.remove(0, caret.getDot()); } catch (BadLocationException ex) { // ignore } } }
/** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { ExTextField target = (ExTextField)getTextComponent(e); target.saveLastEntry(); Document doc = target.getDocument(); Caret caret = target.getCaret(); int offset = SearchHelper.findNextWord(target.getText(), caret.getDot(), target.getText().length(), -1, false, false); if (logger.isDebugEnabled()) logger.debug("offset=" + offset); try { int pos = caret.getDot(); doc.remove(offset, pos - offset); } catch (BadLocationException ex) { // ignore } } }
private void handleToggleComment(Element elem, Document doc, String[] startEnd, boolean add) throws BadLocationException { int start = elem.getStartOffset(); int end = elem.getEndOffset() - 1; if (add) { if (startEnd[1]!=null) { doc.insertString(end, startEnd[1], null); } doc.insertString(start, startEnd[0], null); } else { if (startEnd[1]!=null) { int temp = startEnd[1].length(); doc.remove(end-temp, temp); } doc.remove(start, startEnd[0].length()); } }
/** Clears the current text. */ private void onClear() { int len = textArea.getDocument().getLength(); if (len > 0) { try { textArea.getDocument().remove(0, len); } catch (BadLocationException ex) { // this shouldn't happen throw new IllegalStateException(ex); } } }
void removeText() { if ((p0 != null) && (p1 != null) && (p0.getOffset() != p1.getOffset())) { try { Document doc = c.getDocument(); doc.remove(p0.getOffset(), p1.getOffset() - p0.getOffset()); } catch (BadLocationException e) { } } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } try { int end = textArea.getSelectionStart(); int start = getPreviousWordStart(textArea, end); if (end>start) { textArea.getDocument().remove(start, end-start); } } catch (BadLocationException ex) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { try { // We use the elements instead of calling getLineOfOffset(), // etc. to speed things up just a tad (i.e. micro-optimize). Document document = textArea.getDocument(); int caretPosition = textArea.getCaretPosition(); Element map = document.getDefaultRootElement(); int currentLineNum = map.getElementIndex(caretPosition); Element currentLineElement = map.getElement(currentLineNum); // Always take -1 as we don't want to remove the newline. int currentLineEnd = currentLineElement.getEndOffset()-1; if (caretPosition<currentLineEnd) { document.remove(caretPosition, currentLineEnd-caretPosition); } } catch (BadLocationException ble) { ble.printStackTrace(); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } try { Caret c = textArea.getCaret(); int caretPos = c.getDot(); Document doc = textArea.getDocument(); Element map = doc.getDefaultRootElement(); int lineCount = map.getElementCount(); int line = map.getElementIndex(caretPos); if (line==lineCount-1) { UIManager.getLookAndFeel(). provideErrorFeedback(textArea); return; } Element lineElem = map.getElement(line); caretPos = lineElem.getEndOffset() - 1; c.setDot(caretPos); // Gets rid of any selection. doc.remove(caretPos, 1); // Should be '\n'. } catch (BadLocationException ble) { /* Shouldn't ever happen. */ ble.printStackTrace(); } textArea.requestFocusInWindow(); }