本文整理了Java中javax.swing.JMenuItem.getFontMetrics()
方法的一些代码示例,展示了JMenuItem.getFontMetrics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuItem.getFontMetrics()
方法的具体详情如下:
包路径:javax.swing.JMenuItem
类名称: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));
内容来源于网络,如有侵权,请联系作者删除!