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

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

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

JMenuItem.getFontMetrics介绍

暂无

代码示例

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

private JMenuItem newItem(String text, String iconPath) {
  JMenuItem myMenuItem;
  if (iconPath == null || iconPath.isEmpty()) {
    myMenuItem = new JMenuItem(text);
    myMenuItem.setPreferredSize(new Dimension(myMenuItem.getFontMetrics(myMenuItem.getFont()).stringWidth(text), 20));
  } else {
    ImageIcon icon = new ImageIcon(iconPath);
    myMenuItem = new JMenuItem(text, icon);
    myMenuItem.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
  }
  return myMenuItem;
}

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

private JMenuItem newItem(String text, String iconPath) {
  JMenuItem myMenuItem;
  ImageIcon icon= null;
  int iconPixels = 0;
  if (iconPath == null || iconPath.isEmpty()) {
    myMenuItem = new JMenuItem(text);
  }
  else {
    icon = new ImageIcon(iconPath);
    myMenuItem = new JMenuItem(text, icon);
    iconPixels = icon.getIconWidth();
  }
  FontMetrics fontM = myMenuItem.getFontMetrics(new Font("Default", Font.PLAIN, 12));
  int stringPixels = fontM.stringWidth(text);
  int newWidth = stringPixels + iconPixels;
  newWidth = newWidth < Menu.MINWIDTH ? Menu.MINWIDTH : newWidth;
  newWidth = newWidth > Menu.MAXWIDTH ? Menu.MAXWIDTH : newWidth;
  myMenuItem.setPreferredSize(new Dimension(newWidth, 20)); 
  System.out.println(text + " - " + newWidth);
  return myMenuItem;
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

FontMetrics fm=item.getFontMetrics(item.getFont());
int maxTextWidth=fm.stringWidth(item.getText());
      fm=currItem.getFontMetrics(currItem.getFont());
      maxTextWidth=Math.max(maxTextWidth, fm.stringWidth(currItem.getText()));        
        fm=currItem.getFontMetrics(currItem.getFont());
        maxTextWidth=Math.max(maxTextWidth, fm.stringWidth(currItem.getText()));

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

FontMetrics fm=item.getFontMetrics(acceleratorFont);
int maxTextWidth=fm.stringWidth(getAcceleratorText(item.getAccelerator()));

代码示例来源:origin: com.github.insubstantial/substance

FontMetrics fm = menuItem.getFontMetrics(menuItem.getFont());
FontMetrics fmAccel = menuItem.getFontMetrics(acceleratorFont);

代码示例来源:origin: org.java.net.substance/substance

FontMetrics fm = menuItem.getFontMetrics(menuItem.getFont());
FontMetrics fmAccel = menuItem.getFontMetrics(acceleratorFont);

代码示例来源:origin: com.jidesoft/jide-oss

FontMetrics fm = b.getFontMetrics(font);
FontMetrics fmAccel = b.getFontMetrics(acceleratorFont);

代码示例来源:origin: com.jidesoft/jide-oss

FontMetrics fm = b.getFontMetrics(font);
FontMetrics fmAccel = b.getFontMetrics(acceleratorFont);

代码示例来源:origin: com.jidesoft/jide-oss

FontMetrics fm = b.getFontMetrics(font);
FontMetrics fmAccel = b.getFontMetrics(acceleratorFont);

代码示例来源:origin: khuxtable/seaglass

FontMetrics fm = b.getFontMetrics(font);
FontMetrics fmAccel = b.getFontMetrics(accContext.getStyle().getFont(accContext));

相关文章

JMenuItem类方法