本文整理了Java中javax.swing.JLabel.getFontMetrics()
方法的一些代码示例,展示了JLabel.getFontMetrics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JLabel.getFontMetrics()
方法的具体详情如下:
包路径:javax.swing.JLabel
类名称:JLabel
方法名:getFontMetrics
暂无
代码示例来源:origin: geotools/geotools
/**
* Estimates the maximum display width of the coordinate string based on current integer and
* fractional part lengths.
*
* @return maximum display width
*/
private int getStringWidth() {
FontMetrics fm = label.getFontMetrics(label.getFont());
char[] c = new char[intLen + decLen + 1];
Arrays.fill(c, '0');
String s = String.valueOf(c);
s = s + ", " + s;
return fm.stringWidth(s);
}
代码示例来源:origin: youseries/ureport
public static void main(String[] args) {
FontMetrics fontMetrics=new JLabel().getFontMetrics(new Font("宋体",Font.PLAIN,12));
String text="我是中国人,我来自China,好吧!top和bottom文档描述地很模糊,其实这里我们可以借鉴一下TextView对文本的绘制,"
+ "TextView在绘制文本的时候总会在文本的最外层留出一些内边距,为什么要这样做?因为TextView在绘制文本的时候考虑到了类似读音符号,"
代码示例来源:origin: magefree/mage
int stringWidth = labelRender.getFontMetrics(labelFont).stringWidth(labelText);
int componentWidth = labelRender.getWidth();
代码示例来源:origin: bobbylight/RSyntaxTextArea
FontMetrics fm = label.getFontMetrics(label.getFont());
Object hint = null;
代码示例来源:origin: youseries/ureport
FontMetrics fontMetrics=jlabel.getFontMetrics(font);
int textWidth=fontMetrics.stringWidth(dataText);
代码示例来源:origin: cpesch/RouteConverter
public static int getMaxWidth(String string, int extraWidth) {
if (fontMetrics == null) {
JLabel label = new JLabel();
fontMetrics = label.getFontMetrics(label.getFont());
}
int width = fontMetrics.stringWidth(string);
return width + extraWidth;
}
}
代码示例来源:origin: UNIVALI-LITE/Portugol-Studio
private Dimension getSise(String s) {
FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
int width = fontMetrics.stringWidth(s);
int height = fontMetrics.getHeight();
return new Dimension(width, height);
}
代码示例来源:origin: org.microemu/microemu-javase-swing
public void statusBarChanged(String text) {
FontMetrics metrics = statusBar.getFontMetrics(statusBar.getFont());
statusBar.setPreferredSize(new Dimension(metrics.stringWidth(text), metrics.getHeight()));
statusBar.setText(text);
}
};
代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui
public void setFont(Font font) {
super.setFont(font);
fontMetrics = super.getFontMetrics(font);
resetPreferredSize(true, true);
}
代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit
public void propertiesChanged()
{
// retarded GTK look and feel!
Font font = new JLabel().getFont();
//UIManager.getFont("Label.font");
FontMetrics fm = bufferSetLabel.getFontMetrics(font);
Dimension dim = new Dimension(Math.max(fm.charWidth('E'),Math.max(fm.charWidth('V'),
fm.charWidth('G'))),
fm.getHeight());
bufferSetLabel.setPreferredSize(dim);
bufferSetLabel.setMaximumSize(dim);
} //}}}
代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit
public void propertiesChanged()
{
// retarded GTK look and feel!
Font font = new JLabel().getFont();
//UIManager.getFont("Label.font");
FontMetrics fm = overwrite.getFontMetrics(font);
Dimension dim = new Dimension(
Math.max(fm.charWidth('-'),fm.charWidth('O')) + 1,
fm.getHeight());
overwrite.setPreferredSize(dim);
overwrite.setMaximumSize(dim);
} //}}}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javaee-project
private void resize() {
int width = (new Double(jLabelDesc.getFontMetrics(jLabelDesc.getFont()).getStringBounds(jLabelDesc.getText(), getGraphics()).getWidth() / 2.7)).intValue() + 40;
int height = (jLabelDesc.getFont().getSize() * 5) + 100;
if (width < 400)
width = 400;
if (height < 160)
height = 160;
java.awt.Dimension dim = new java.awt.Dimension(width, height);
setMinimumSize(dim);
setPreferredSize(dim);
}
代码示例来源:origin: freeplane/freeplane
protected FontMetrics getFontMetrics() {
if (!useFractionalMetrics()) {
return super.getFontMetrics(getFont());
}
fmg.setFont(getFont());
final FontMetrics fontMetrics = fmg.getFontMetrics();
return fontMetrics;
}
代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl
private void setupFont() {
plainFont = OWLRendererPreferences.getInstance().getFont();
plainFontHeight = iconLabel.getFontMetrics(plainFont).getHeight();
boldFont = plainFont.deriveFont(Font.BOLD);
textPane.setFont(plainFont);
}
代码示例来源:origin: org.protege/protege-editor-owl
private void setupFont() {
plainFont = OWLRendererPreferences.getInstance().getFont();
plainFontHeight = iconLabel.getFontMetrics(plainFont).getHeight();
boldFont = plainFont.deriveFont(Font.BOLD);
textPane.setFont(plainFont);
}
代码示例来源:origin: protegeproject/protege
private void prepareRenderer(JLabel label, Object value) {
final Font font = OWLRendererPreferences.getInstance().getFont();
label.setFont(font);
setText(value, label);
setIcon(value, label);
boldIfNecessary(value, label);
if (value == null){
// so that null does not render with no height
label.setPreferredSize(new Dimension(label.getPreferredSize().width, label.getFontMetrics(font).getHeight()));
}
}
代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl
private void prepareRenderer(JLabel label, Object value) {
final Font font = OWLRendererPreferences.getInstance().getFont();
label.setFont(font);
setText(value, label);
setIcon(value, label);
boldIfNecessary(value, label);
if (value == null){
// so that null does not render with no height
label.setPreferredSize(new Dimension(label.getPreferredSize().width, label.getFontMetrics(font).getHeight()));
}
}
代码示例来源:origin: edu.stanford.protege/protege-editor-owl
private void prepareRenderer(JLabel label, Object value) {
final Font font = OWLRendererPreferences.getInstance().getFont();
label.setFont(font);
setText(value, label);
setIcon(value, label);
boldIfNecessary(value, label);
if (value == null){
// so that null does not render with no height
label.setPreferredSize(new Dimension(label.getPreferredSize().width, label.getFontMetrics(font).getHeight()));
}
}
代码示例来源:origin: org.protege/protege-editor-owl
private void prepareRenderer(JLabel label, Object value) {
final Font font = OWLRendererPreferences.getInstance().getFont();
label.setFont(font);
setText(value, label);
setIcon(value, label);
boldIfNecessary(value, label);
if (value == null){
// so that null does not render with no height
label.setPreferredSize(new Dimension(label.getPreferredSize().width, label.getFontMetrics(font).getHeight()));
}
}
代码示例来源:origin: net.java.dev.swing-layout/swing-layout
private int getLabelBaseline(JLabel label, int height) {
Icon icon = (label.isEnabled()) ? label.getIcon() :
label.getDisabledIcon();
FontMetrics fm = label.getFontMetrics(label.getFont());
resetRects(label, height);
SwingUtilities.layoutCompoundLabel(label, fm,
"a", icon, label.getVerticalAlignment(),
label.getHorizontalAlignment(), label.getVerticalTextPosition(),
label.getHorizontalTextPosition(), viewRect, iconRect, textRect,
label.getIconTextGap());
return textRect.y + fm.getAscent();
}
内容来源于网络,如有侵权,请联系作者删除!