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

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

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

JTextPane.getFontMetrics介绍

暂无

代码示例

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

private void setupFont() {
  plainFont = new Font("Lucida Grande", Font.PLAIN, 14);
  plainFontHeight = trgQueryTextPane.getFontMetrics(plainFont).getHeight();
  int[] widths = trgQueryTextPane.getFontMetrics(plainFont).getWidths();
  int sum = 0;
  for (int i = 0; i < widths.length; i++) {
    int j = widths[i];
    sum += j;
  }
  plainFontWidth = sum / widths.length;
  trgQueryTextPane.setFont(plainFont);
}

代码示例来源:origin: net.sf.squirrel-sql.plugins/graph

private void recalculateDDLFrameSize(JInternalFrame ddlFrame, JTextPane txtDDL, String[] lines)
{
 FontMetrics fm = txtDDL.getFontMetrics(txtDDL.getFont());
 int txtHeight = fm.getHeight() * lines.length;
 int txtWidht = 0;
 for (int i = 0; i < lines.length; i++)
 {
   txtWidht = Math.max(txtWidht, fm.stringWidth(lines[i]));
 }
 BasicInternalFrameUI ui = (BasicInternalFrameUI) ddlFrame.getUI();
 int titleHeight = ui.getNorthPane().getHeight();
 ddlFrame.setSize(txtWidht + 20, txtHeight + titleHeight + 20);
}

代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler

/**
 * Returns the width, in pixels
 */
private int lineNumberWidth(JTextPane textPane) {
  int lineCount = getEtalon();
  setLineNumberWidth(textPane.getFontMetrics(textPane.getFont())
      .stringWidth(lineCount + " "));
  return getLineNumberWidth();
}

代码示例来源:origin: stackoverflow.com

/**
 * Return an int containing the wrapped line index at the given position
 * @param component JTextPane
 * @param int pos
 * @return int
 */
public int getLineNumber(JTextPane component, int pos) 
{
 int posLine;
 int y = 0;
 try
 {
  Rectangle caretCoords = component.modelToView(pos);
  y = (int) caretCoords.getY();
 }
 catch (BadLocationException ex)
 {
 }
 int lineHeight = component.getFontMetrics(component.getFont()).getHeight();
 posLine = (y / lineHeight) + 1;
 return posLine;
}

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

StringBuffer currentLine = new StringBuffer();
int linesTarget = 1;
FontMetrics m = trgQueryTextPane.getFontMetrics(plainFont);
for (String splitst : split) {
  boolean space = false;

代码示例来源:origin: blurpy/kouchat

final FontMetrics fm = viewerTP.getFontMetrics(viewerTP.getFont());
final int width = fm.charWidth('_') * 80;
final int height = fm.getHeight() * 24;

代码示例来源:origin: vasl-developers/vasl

private void RebuildStyles()
{
  send(" ");
  StyleConstants.setAlignment(m_objMainStyle, StyleConstants.ALIGN_LEFT);
  StyleConstants.setFontFamily(m_objMainStyle, m_objChatterFont.getFamily());
  StyleConstants.setFontSize(m_objMainStyle, m_objChatterFont.getSize());
  StyleConstants.setSpaceAbove(m_objMainStyle, 2);
  StyleConstants.setSpaceBelow(m_objMainStyle, 2);
  send("- Chatter font changed");
  send(" ");
  FontMetrics l_objFM = m_objChatPanel.getFontMetrics(m_objChatterFont);
  float l_f = (float)l_objFM.stringWidth(BEFORE_CATEGORY + ASLDiceBot.OTHER_CATEGORY + "XXX");
  TabStop[] lar_objTabs = new TabStop[10]; // this sucks
  for(int l_i = 0; l_i < lar_objTabs.length; l_i++)
  {
     lar_objTabs[l_i] = new TabStop(l_f * (l_i + 1), TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
  }
  TabSet l_objTabset = new TabSet(lar_objTabs);
  StyleConstants.setTabSet(m_objMainStyle, new TabSet(new TabStop[0]));
  StyleConstants.setTabSet(m_objMainStyle, l_objTabset);
  m_objChatPanel.setParagraphAttributes(m_objMainStyle, true);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

FontMetrics fontMetrics = pane.getFontMetrics(font);
try {
  Rectangle rectangle = new Rectangle(

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

Element rootElement = org.openide.text.NbDocument.findLineRootElement(doc);
int lineCount = rootElement.getElementCount();
int height = textPane.getFontMetrics(textPane.getFont()).getHeight() * (lineCount + 1);
int maxWidth = 0;
for (int line = 0; line < lineCount; line++) {
    e.printStackTrace();
  int lineLength = textPane.getFontMetrics(textPane.getFont()).stringWidth(text);
  if (lineLength > maxWidth) {
    maxWidth = lineLength;

相关文章

JTextPane类方法