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

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

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

JEditorPane.getFontMetrics介绍

暂无

代码示例

代码示例来源:origin: openstreetmap/osmembrane

/**
 * Sets the hint text
 * 
 * @param hintText
 *            the hintText to set
 */
protected void setHintText(String hintText) {
  if ((hintText == null) || (hintText.isEmpty())) {
    hintText = I18N.getInstance().getString("View.Inspector.NoHint");
  }
  StringBuilder sb = new StringBuilder();
  FontMetrics fm = hintLabel.getFontMetrics(hintLabel.getFont());
  int lineWidth = 0;
  for (String word : hintText.split("\\s")) {
    int thisWidth = fm.stringWidth(word + " ");
    // if this line is wider than possible, make a new line
    if (lineWidth + thisWidth >= hint.getWidth() - 8) {
      sb.append("<br />" + word + " ");
      lineWidth = 0;
    } else {
      // append
      lineWidth += thisWidth;
      sb.append(word + " ");
    }
  }
  hintLabel.setText("<html><center><br /><p>" + sb.toString()
      + "</p></center></html>");
}

代码示例来源:origin: dcaoyuan/nbscala

FontMetrics fm = editorPane.getFontMetrics(editorPane.getFont());
int size = 2*fm.getLeading() + fm.getMaxAscent() + fm.getMaxDescent() + 2;
editorPane.setPreferredSize(new Dimension(30*size, (int) (1*size)));

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-propertyeditors

gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
FontMetrics metrics = editorPane.getFontMetrics(editorPane.getFont());
int columnWidth = metrics.charWidth('m'); // cloned code from JTextArea
int rowHeight = metrics.getHeight();

代码示例来源:origin: de.sciss/jsyntaxpane

super.paintComponent(g);
FontMetrics fontMetrics = editor.getFontMetrics(editor.getFont());
Insets insets = getInsets();
int currentLine = -1;

代码示例来源: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-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.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);
  }
 }
}

相关文章

JEditorPane类方法