javax.swing.JTextPane.getCaretPosition()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中javax.swing.JTextPane.getCaretPosition()方法的一些代码示例,展示了JTextPane.getCaretPosition()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.getCaretPosition()方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:getCaretPosition

JTextPane.getCaretPosition介绍

暂无

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Highlights the sentence that is currently being edited
 */
private void highlightEditedSentence() {
 highlightSentence(textPane.getCaretPosition());
}

代码示例来源:origin: ron190/jsql-injection

boolean isCaretAtEnd = this.getProxy().getCaretPosition() == this.getProxy().getDocument().getLength();

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui

public int getCaretPosition() {
 return jtpMain.getCaretPosition();
}

代码示例来源:origin: edu.stanford.nlp/stanford-parser

/**
 * Highlights the sentence that is currently being edited
 */
private void highlightEditedSentence() {
 highlightSentence(textPane.getCaretPosition());
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui

void insertToInputArea(String message) {
  if (message==null)
    return;
  try {
    outbox.getDocument().insertString(outbox.getCaretPosition(), message, null);
  } catch (BadLocationException ex) {
    Exceptions.printStackTrace(ex);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui

public void actionPerformed(ActionEvent e) {
    try {
      out.getDocument().insertString(out.getCaretPosition(),outText, null);
      out.requestFocus();
    } catch (BadLocationException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
}

代码示例来源:origin: net.sf.ingenias/ingeniasjgraphmod

public void actionPerformed(ActionEvent e) {
    Document doc = editorComponent.getDocument();
    try {
      doc.insertString(editorComponent
          .getCaretPosition(), "\n", null);
    } catch (BadLocationException e1) {
      e1.printStackTrace();
    }
  }
});

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

private void caretUpdate(javax.swing.event.CaretEvent evt) {
  try {
    int pos = editor.getCaretPosition();
    int line = getLineOfOffset(pos);
    int lineStartOffset = getLineStartOffset(line);
    caretInfoLabel.setText((line + 1) + ":" + (pos - lineStartOffset + 1));
  } catch (BadLocationException e) {
    caretInfoLabel.setText(e.toString());
  }
}

代码示例来源:origin: beanshell/beanshell

public void cut() {
  if (text.getCaretPosition() < cmdStart) {
    super.copy();
  } else {
    super.cut();
  }
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui

/**
 * Method for inserting a break (BR) element
 */
private void insertBreak() throws IOException, BadLocationException, RuntimeException {
 int caretPos = jtpMain.getCaretPosition();
 htmlKit.insertHTML(htmlDoc, caretPos, "<BR>", 0, 0, HTML.Tag.BR);
 jtpMain.setCaretPosition(caretPos + 1);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui

public void actionPerformed(ActionEvent e) {
    String outText = "ISSUE:123";//NOI18N
    try {
      out.requestFocus();
      int caretPosition = out.getCaretPosition();
      out.getDocument().insertString( caretPosition, " " + outText + " ", null); // NOI18N
      out.setSelectionStart(caretPosition+7);
      out.setSelectionEnd(caretPosition+outText.length()+1);
    } catch (BadLocationException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui

public void actionPerformed(ActionEvent e) {
    String outText = "FILE:foo/bar/Test.java:23"; // NOI18N
    try {
      out.requestFocus();
      int caretPosition = out.getCaretPosition();
      out.getDocument().insertString( caretPosition, " " + outText + " ", null); // NOI18N
      out.setSelectionStart(caretPosition+6);
      out.setSelectionEnd(caretPosition+outText.length()+1);
    } catch (BadLocationException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui

/**
 * Method for inserting Unicode characters via the UnicodeDialog class
 */
public void insertUnicodeChar(String sChar) throws IOException, BadLocationException, RuntimeException {
 int caretPos = jtpMain.getCaretPosition();
 if (sChar != null) {
  htmlDoc.insertString(caretPos, sChar, jtpMain.getInputAttributes());
  jtpMain.setCaretPosition(caretPos + 1);
 }
}

代码示例来源:origin: beanshell/beanshell

private void forceCaretMoveToEnd() {
  if (text.getCaretPosition() < cmdStart) {
    // move caret first!
    text.setCaretPosition(textLength());
  }
  text.repaint();
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui

/**
 * Method for inserting a non-breaking space (&nbsp;)
 */
private void insertNonbreakingSpace() throws IOException, BadLocationException, RuntimeException {
 int caretPos = jtpMain.getCaretPosition();
 htmlDoc.insertString(caretPos, "\240", jtpMain.getInputAttributes());
 jtpMain.setCaretPosition(caretPos + 1);
}

代码示例来源:origin: fr.inria.wimmics/kggui

private CompoundEdit startCompoundEdit(UndoableEdit anEdit)
{
  //  Track Caret and Document information of this compound edit
  lastOffset = editor.getCaretPosition();
  lastLength = editor.getStyledDocument().getLength();
  //  The compound edit is used to store incremental edits
  compoundEdit = new MyCompoundEdit();
  compoundEdit.addEdit( anEdit );
  //  The compound edit is added to the UndoManager. All incremental
  //  edits stored in the compound edit will be undone/redone at once
  addEdit( compoundEdit );
  return compoundEdit;
}

代码示例来源:origin: Wimmics/corese

private CompoundEdit startCompoundEdit(UndoableEdit anEdit)
{
  //  Track Caret and Document information of this compound edit
  lastOffset = editor.getCaretPosition();
  lastLength = editor.getStyledDocument().getLength();
  //  The compound edit is used to store incremental edits
  compoundEdit = new MyCompoundEdit();
  compoundEdit.addEdit( anEdit );
  //  The compound edit is added to the UndoManager. All incremental
  //  edits stored in the compound edit will be undone/redone at once
  addEdit( compoundEdit );
  return compoundEdit;
}

代码示例来源:origin: org.vesalainen.dsql/dsql

@Override
public void replace(String newText, int start, int end)
{
  setOff();
  int save = sqlPane.getCaretPosition();
  sqlPane.setCaretPosition(start);
  sqlPane.moveCaretPosition(end);
  sqlPane.replaceSelection(newText);
  sqlPane.setCaretPosition(save);
  setOn();
}

代码示例来源:origin: beryx/text-io

public void replaceInput(String message, boolean preserveCaretPosition) {
  int oldCaretPosition = textPane.getCaretPosition();
  try {
    document.remove(startReadLen, document.getLength() - startReadLen);
    document.insertString(document.getLength(), message, textPane.getInputAttributes().copyAttributes());
  } catch (BadLocationException e) {
    e.printStackTrace();
  } catch (Exception e) {
    logger.error("Cannot insert input text", e);
  }
  int newCaretPosition = (preserveCaretPosition && oldCaretPosition <= document.getLength()) ? oldCaretPosition : document.getLength();
  textPane.setCaretPosition(newCaretPosition);
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui

/**
 * Method for inserting an image from a URL
 */
public void insertURLImage() throws IOException, BadLocationException, RuntimeException {
 ImageURLDialog iurlDialog = new ImageURLDialog(this.getFrame(), Translatrix
   .getTranslationString("ImageURLDialogTitle"), true);
 iurlDialog.pack();
 iurlDialog.setVisible(true);
 String whatImage = iurlDialog.getURL();
 if (whatImage != null) {
  int caretPos = jtpMain.getCaretPosition();
  htmlKit.insertHTML(htmlDoc, caretPos, "<IMG SRC=\"" + whatImage + "\">", 0, 0, HTML.Tag.IMG);
  jtpMain.setCaretPosition(caretPos + 1);
  refreshOnUpdate();
 }
}

相关文章

JTextPane类方法