當前位置: 首頁>>代碼示例>>Java>>正文


Java Font.getName方法代碼示例

本文整理匯總了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));
}
 
開發者ID:ser316asu,項目名稱:Neukoelln_SER316,代碼行數:13,代碼來源:FontDialog.java

示例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
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:FontInfo.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:ComponentLine.java

示例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
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:Editor.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:PatchedHtmlRenderer.java

示例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
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:HTMLLabel.java

示例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());
}
 
開發者ID:berniejenny,項目名稱:MapAnalyst,代碼行數:8,代碼來源:MapObjectImpl.java

示例8: CloneFont

import java.awt.Font; //導入方法依賴的package包/類
public static Font CloneFont(Font origem) {
    return new Font(origem.getName(), origem.getStyle(), origem.getSize());
}
 
開發者ID:chcandido,項目名稱:brModelo,代碼行數:4,代碼來源:Elementar.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:42,代碼來源:WindowsLookAndFeel.java

示例10: smallerFont

import java.awt.Font; //導入方法依賴的package包/類
private static Font smallerFont(Font font) {
    return new Font(font.getName(), font.getStyle(), font.getSize() - 2);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:4,代碼來源:ProfilerXYTooltipPainter.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:65,代碼來源:SyntaxColoringPanel.java

示例12: encode

import java.awt.Font; //導入方法依賴的package包/類
public static String encode(Font f) {
  return f.getName() + "," + f.getSize();
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:4,代碼來源:FontConfigurer.java

示例13: PFont

import java.awt.Font; //導入方法依賴的package包/類
/**
 * @param font
 */
public PFont(final Font font) {
    super(font.getName(), font.getStyle(), font.getSize());
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:7,代碼來源:PFont.java


注:本文中的java.awt.Font.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。