本文整理汇总了Java中java.awt.Font.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Font.getName方法的具体用法?Java Font.getName怎么用?Java Font.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Font
的用法示例。
在下文中一共展示了Font.getName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fontChanged
import java.awt.Font; //导入方法依赖的package包/类
void fontChanged(ActionEvent e) {
int[] sizes = {8,10,13,16,18,24,32};
int size = 16;
String face;
Font font = sample.getFont();
if (fontSizeCB.getSelectedIndex() > 0)
size = sizes[fontSizeCB.getSelectedIndex()-1];
if (fontFamilyCB.getSelectedIndex() >0)
face = (String)fontFamilyCB.getSelectedItem();
else face = font.getName();
sample.setFont(new Font(face,Font.PLAIN, size));
}
示例2: FontInfo
import java.awt.Font; //导入方法依赖的package包/类
FontInfo(Font origFont, JTextComponent textComponent, FontRenderContext frc, float rowHeightCorrection, int textZoom) {
renderFont = (textZoom != 0)
? new Font(origFont.getName(), origFont.getStyle(), Math.max(origFont.getSize() + textZoom, 1))
: origFont;
char defaultChar = 'A';
String defaultCharText = String.valueOf(defaultChar);
TextLayout defaultCharTextLayout = new TextLayout(defaultCharText, renderFont, frc); // NOI18N
TextLayout rowHeightTextLayout = new TextLayout("A_|B", renderFont, frc);
// Round the ascent to eliminate long mantissa without any visible effect on rendering.
updateRowHeight(rowHeightTextLayout, rowHeightCorrection);
// Ceil fractions to whole numbers since this measure may be used for background rendering
charWidth = (float) Math.ceil(defaultCharTextLayout.getAdvance());
LineMetrics lineMetrics = renderFont.getLineMetrics(defaultCharText, frc);
underlineAndStrike[0] = lineMetrics.getUnderlineOffset() * rowHeightCorrection;
underlineAndStrike[1] = lineMetrics.getUnderlineThickness();
underlineAndStrike[2] = lineMetrics.getStrikethroughOffset() * rowHeightCorrection;
underlineAndStrike[3] = lineMetrics.getStrikethroughThickness();
if (LOG.isLoggable(Level.FINE)) {
FontMetrics fm = textComponent.getFontMetrics(origFont); // From original font
LOG.fine("Orig Font=" + origFont + // NOI18N
"\n " + this + ", charWidth=" + charWidth + ", textZoom=" + textZoom + // NOI18N
"\n rowHeightCorrection=" + rowHeightCorrection + // NOI18N
", underlineO/T=" + underlineAndStrike[0] + "/" + underlineAndStrike[1] + // NOI18N
", strikethroughO/T=" + underlineAndStrike[2] + "/" + underlineAndStrike[3] + // NOI18N
"\n FontMetrics (for comparison; without-RHC): fm-line-height=" + fm.getHeight() + // NOI18N
", fm-ascent,descent,leading=" + fm.getAscent() + "," + fm.getDescent() + "," + fm.getLeading() + // NOI18N
"\n"); // NOI18N
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, "FontInfo creation stacktrace", new Exception()); // NOI18N
}
}
}
示例3: createFont
import java.awt.Font; //导入方法依赖的package包/类
private Font createFont(Font attrFont, Font defaultFont) {
if ( !Config.getDefault().isUseFont()) {
return defaultFont;
}
String name = defaultFont.getName();
int size = defaultFont.getSize();
int style = attrFont.getStyle();
return new Font(name, style, size);
}
示例4: getString
import java.awt.Font; //导入方法依赖的package包/类
private String getString(Font font) {
String style = ""; // NOI18N
if (font.isBold()) {
style += "bold"; // NOI18N
}
if (font.isItalic()) {
style += " italic"; // NOI18N
}
else {
style += " plain"; // NOI18N
}
return "[" + font.getName() + ", " + style + ", " + font.getSize() + "]"; // NOI18N
}
示例5: deriveFont
import java.awt.Font; //导入方法依赖的package包/类
/**
* Workaround for Apple bug 3644261 - after using form editor, all boldface
* fonts start showing up with incorrect metrics, such that all boldface
* fonts in the entire IDE are displayed 12px below where they should be.
* Embarrassing and awful.
*/
private static final Font deriveFont(Font f, int style) {
// return f.deriveFont(style);
// see #49973 for details.
Font result = Utilities.isMac() ? new Font(f.getName(), style, f.getSize()) : f.deriveFont(style);
return result;
}
示例6: setText
import java.awt.Font; //导入方法依赖的package包/类
public void setText(String value) {
txt = value;
Font font = getFont();
Color fgColor = getForeground();
Color bgColor = getBackground();
value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); //NOI18N
value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); //NOI18N
String fgText = "rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ")"; //NOI18N
String bgText = isOpaque() ? "rgb(" + bgColor.getRed() + "," + bgColor.getGreen() + "," + bgColor.getBlue() + ")" : null; //NOI18N
String alignText = null;
switch (halign) {
case SwingConstants.CENTER:
alignText = "center"; //NOI18N
break;
case SwingConstants.RIGHT:
case SwingConstants.TRAILING:
alignText = "right"; //NOI18N
break;
}
String bodyFlags = "text=\"" + fgText + "\""; //NOI18N
if (bgText != null) bodyFlags += " bgcolor=\"" + bgText + "\""; //NOI18N
if (alignText != null) bodyFlags += " align=\"" + alignText + "\""; //NOI18N
super.setText("<html><body " + bodyFlags + " style=\"font-size: " + font.getSize() //NOI18N
+ "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"); //NOI18N
}
示例7: getDefaultFont
import java.awt.Font; //导入方法依赖的package包/类
public static Font getDefaultFont() {
Font f = UIManager.getDefaults().getFont("TextField.font");
if (f == null) {
f = Font.decode(null);
}
return new Font(f.getName(), Font.BOLD, f.getSize());
}
示例8: CloneFont
import java.awt.Font; //导入方法依赖的package包/类
public static Font CloneFont(Font origem) {
return new Font(origem.getName(), origem.getStyle(), origem.getSize());
}
示例9: configureValue
import java.awt.Font; //导入方法依赖的package包/类
protected Object configureValue(Object value) {
if (value instanceof Font) {
Font font = (Font)value;
if ("MS Sans Serif".equals(font.getName())) {
int size = font.getSize();
// 4950968: Workaround to mimic the way Windows maps the default
// font size of 6 pts to the smallest available bitmap font size.
// This happens mostly on Win 98/Me & NT.
int dpi;
try {
dpi = Toolkit.getDefaultToolkit().getScreenResolution();
} catch (HeadlessException ex) {
dpi = 96;
}
if (Math.round(size * 72F / dpi) < 8) {
size = Math.round(8 * dpi / 72F);
}
Font msFont = new FontUIResource("Microsoft Sans Serif",
font.getStyle(), size);
if (msFont.getName() != null &&
msFont.getName().equals(msFont.getFamily())) {
font = msFont;
} else if (size != font.getSize()) {
font = new FontUIResource("MS Sans Serif",
font.getStyle(), size);
}
}
if (FontUtilities.fontSupportsDefaultEncoding(font)) {
if (!(font instanceof UIResource)) {
font = new FontUIResource(font);
}
}
else {
font = FontUtilities.getCompositeFontUIResource(font);
}
return font;
}
return super.configureValue(value);
}
示例10: smallerFont
import java.awt.Font; //导入方法依赖的package包/类
private static Font smallerFont(Font font) {
return new Font(font.getName(), font.getStyle(), font.getSize() - 2);
}
示例11: modifyFont
import java.awt.Font; //导入方法依赖的package包/类
private AttributeSet modifyFont (AttributeSet category, Font f) {
String fontName = f.getName ();
Integer fontSize = new Integer (f.getSize ());
Boolean bold = Boolean.valueOf (f.isBold ());
Boolean italic = Boolean.valueOf (f.isItalic ());
boolean isDefault = "default".equals (
category.getAttribute (StyleConstants.NameAttribute)
);
if (fontName.equals (
getDefault (currentLanguage, category, StyleConstants.FontFamily)
) && !isDefault)
fontName = null;
if (fontSize.equals (
getDefault (currentLanguage, category, StyleConstants.FontSize)
) && !isDefault)
fontSize = null;
if (bold.equals (getDefault (currentLanguage, category, StyleConstants.Bold))
)
bold = null;
else
if (bold.equals (Boolean.FALSE) &&
getDefault (currentLanguage, category, StyleConstants.Bold) == null
)
bold = null;
if (italic.equals (getDefault (currentLanguage, category, StyleConstants.Italic))
)
italic = null;
else
if (italic.equals (Boolean.FALSE) &&
getDefault (currentLanguage, category, StyleConstants.Italic) == null
)
italic = null;
SimpleAttributeSet c = new SimpleAttributeSet (category);
if (fontName != null)
c.addAttribute (
StyleConstants.FontFamily,
fontName
);
else
c.removeAttribute (StyleConstants.FontFamily);
if (fontSize != null)
c.addAttribute (
StyleConstants.FontSize,
fontSize
);
else
c.removeAttribute (StyleConstants.FontSize);
if (bold != null)
c.addAttribute (
StyleConstants.Bold,
bold
);
else
c.removeAttribute (StyleConstants.Bold);
if (italic != null)
c.addAttribute (
StyleConstants.Italic,
italic
);
else
c.removeAttribute (StyleConstants.Italic);
return c;
}
示例12: encode
import java.awt.Font; //导入方法依赖的package包/类
public static String encode(Font f) {
return f.getName() + "," + f.getSize();
}
示例13: PFont
import java.awt.Font; //导入方法依赖的package包/类
/**
* @param font
*/
public PFont(final Font font) {
super(font.getName(), font.getStyle(), font.getSize());
}