javax.swing.JEditorPane.modelToView()方法的使用及代码示例

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

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

JEditorPane.modelToView介绍

暂无

代码示例

代码示例来源:origin: bobbylight/RSyntaxTextArea

r = textArea.modelToView(textArea.getDocument().getLength()-1);
r = textArea.modelToView(textArea.getDocument().getLength()-1);
if (r.y+r.height>d.height) {
  d.height = r.y + r.height + 5;

代码示例来源:origin: javax.help/javahelp

public void run() {
    try {
      Rectangle rec = html.modelToView(pos);
      if (rec != null) {
        html.scrollRectToVisible(rec);
      }
    } catch (BadLocationException bl) {
    }
  }
}

代码示例来源:origin: org.sonarsource.sslr/sslr-toolkit

@Override
public void scrollSourceCodeTo(@Nullable AstNode astNode) {
 if (astNode != null && astNode.hasToken()) {
  int visibleLines = sourceCodeEditorPane.getVisibleRect().height / sourceCodeEditorPane.getFontMetrics(sourceCodeEditorPane.getFont()).getHeight();
  int line = astNode.getToken().getLine() + visibleLines / 2;
  try {
   sourceCodeEditorPane.scrollRectToVisible(sourceCodeEditorPane.modelToView(0));
   sourceCodeEditorPane.scrollRectToVisible(sourceCodeEditorPane.modelToView(lineOffsets.getOffset(line, 0)));
  } catch (BadLocationException e) {
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: org.codehaus.sonar.sslr/sslr-devkit

private void scrollToFirstSelectedPath() {
 TreePath selectedPath = astTree.getSelectionPath();
 if (selectedPath != null) {
  DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) selectedPath.getLastPathComponent();
  AstNode astNode = getAstNodeFromUserObject(treeNode.getUserObject());
  int visibleLines = codeEditor.getVisibleRect().height / codeEditor.getFontMetrics(codeEditor.getFont()).getHeight();
  int line = astNode.getToken().getLine() + visibleLines / 2;
  try {
   codeEditor.scrollRectToVisible(codeEditor.modelToView(0));
   codeEditor.scrollRectToVisible(codeEditor.modelToView(lineOffsets.getOffset(line, 0)));
  } catch (BadLocationException e) {
   LOG.error("Error with the scrolling", e);
  }
 }
}

代码示例来源:origin: org.codehaus.sonar.sslr/sslr-toolkit

@Override
public void scrollSourceCodeTo(@Nullable AstNode astNode) {
 if (astNode != null && astNode.hasToken()) {
  int visibleLines = sourceCodeEditorPane.getVisibleRect().height / sourceCodeEditorPane.getFontMetrics(sourceCodeEditorPane.getFont()).getHeight();
  int line = astNode.getToken().getLine() + visibleLines / 2;
  try {
   sourceCodeEditorPane.scrollRectToVisible(sourceCodeEditorPane.modelToView(0));
   sourceCodeEditorPane.scrollRectToVisible(sourceCodeEditorPane.modelToView(lineOffsets.getOffset(line, 0)));
  } catch (BadLocationException e) {
   throw Throwables.propagate(e);
  }
 }
}

代码示例来源:origin: SonarSource/sslr

@Override
public void scrollSourceCodeTo(@Nullable AstNode astNode) {
 if (astNode != null && astNode.hasToken()) {
  int visibleLines = sourceCodeEditorPane.getVisibleRect().height / sourceCodeEditorPane.getFontMetrics(sourceCodeEditorPane.getFont()).getHeight();
  int line = astNode.getToken().getLine() + visibleLines / 2;
  try {
   sourceCodeEditorPane.scrollRectToVisible(sourceCodeEditorPane.modelToView(0));
   sourceCodeEditorPane.scrollRectToVisible(sourceCodeEditorPane.modelToView(lineOffsets.getOffset(line, 0)));
  } catch (BadLocationException e) {
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: org.nuiton.thirdparty/rsyntaxtextarea

/**
 * Workaround for JEditorPane not returning its proper preferred size
 * when rendering HTML until after layout already done.  See
 * http://forums.sun.com/thread.jspa?forumID=57&threadID=574810 for a
 * discussion.
 */
void fixSize() {
  Dimension d = textArea.getPreferredSize();
  Rectangle r = null;
  try {
    r = textArea.modelToView(textArea.getDocument().getLength()-1);
    d.height = r.y + r.height;
    // Ensure the text area doesn't start out too tall or wide.
    d = textArea.getPreferredSize();
    d.width = Math.min(d.width+25, 320);
    d.height = Math.min(d.height, 150);
    textArea.setPreferredSize(d);
  } catch (BadLocationException ble) { // Never happens
    ble.printStackTrace();
  }
  pack(); // Must re-pack to calculate proper size.
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

private void setCaretPosition(int carpos) {
try {
  Rectangle bubble = editorPane.modelToView(carpos);
  Rectangle viewRect = textScrollPane.getViewport().getViewRect();

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages

public void run() {
    Iterator it = TopComponent.getRegistry ().getOpened ().iterator ();
    while (it.hasNext ()) {
      TopComponent tc = (TopComponent) it.next ();
      EditorCookie ec = tc.getLookup ().lookup (EditorCookie.class);
      if (ec == null) continue;
      JEditorPane[] eps = ec.getOpenedPanes ();
      if (eps == null) continue;
      int i, k = eps.length;
      for (i = 0; i < k; i++) {
        if (eps [i].getDocument () == doc) {
          final JEditorPane ep = eps [i];
          if (ep != null)
            try {
              ep.scrollRectToVisible (ep.modelToView (offset));
            } catch (BadLocationException ex) {
              ErrorManager.getDefault ().notify (ex);
            }
        }
      }
    }
  }
});

代码示例来源:origin: com.fifesoft/rsyntaxtextarea

r = textArea.modelToView(textArea.getDocument().getLength()-1);
r = textArea.modelToView(textArea.getDocument().getLength()-1);
if (r.y+r.height>d.height) {
  d.height = r.y + r.height + 5;

相关文章

JEditorPane类方法