Example usage for java.awt Font getSize

List of usage examples for java.awt Font getSize

Introduction

In this page you can find the example usage for java.awt Font getSize.

Prototype

public int getSize() 

Source Link

Document

Returns the point size of this Font , rounded to an integer.

Usage

From source file:ComponentHier.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JComponent Hierarchy");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Font font = (Font) UIManager.get("Tree.font");
    font = new Font(font.getFontName(), Font.BOLD, font.getSize() - 3);
    UIManager.put("Tree.font", font);

    Vector jEditorPaneVector = new NamedVector("JEditorPane", new Object[] { "JTextPane" });

    Vector jTextFieldVector = new NamedVector("JTextField", new Object[] { "JPasswordField" });

    Vector jTextComponentVector = new NamedVector("JTextComponent",
            new Object[] { jEditorPaneVector, "JTextArea", jTextFieldVector });

    Vector jLayeredPaneVector = new NamedVector("JLayeredPane", new Object[] { "JDesktopPane" });

    Vector jToggleButtonVector = new NamedVector("JToggleButton", new Object[] { "JCheckBox", "JRadioButton" });

    Vector jMenuItemVector = new NamedVector("JMenuItem",
            new Object[] { "JCheckBoxMenuItem", "JMenu", "JRadioButtonMenuItem" });

    Vector abstractButtonVector = new NamedVector("Abstract Button",
            new Object[] { "JButton", jMenuItemVector, jToggleButtonVector });

    Object jComponentNodes[] = { abstractButtonVector, "JColorChooser", "JComboBox", "JFileChooser",
            "JInternalFrame", "JLabel", jLayeredPaneVector, "JList", "JMenuBar", "JOptionPane", "JPanel",
            "JPopupMenu", "JProgressBar", "JRootPane", "JScrollBar", "JScrollPane", "JSeparator", "JSlider",
            "JSplitPane", "JTabbedPane", "JTable", jTextComponentVector, "JToolBar", "JTree", "JViewPort" };
    Vector jComponentVector = new NamedVector("JComponent", jComponentNodes);

    Object rootNodes[] = { jComponentVector };
    Vector rootVector = new NamedVector("Root", rootNodes);

    JTree tree = new JTree(rootVector);
    tree.putClientProperty("JTree.lineStyle", "Angled");

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(250, 480);// w w  w  .j a  v a  2  s  .c  om
    frame.setVisible(true);
}

From source file:Main.java

public static JLabel modifyLabelFont(JLabel label, int style, int delta) {
    Font font = label.getFont();
    label.setFont(font.deriveFont(style, font.getSize() + delta));
    label.setForeground(new Color(140, 140, 140));
    return label;
}

From source file:Main.java

/** 
 * Sets all used fonts for displaying to the specified font df
 * <br>Use with care! //from   w  w  w  .j av a 2  s . c o m
 */
public static void setUIFont(final Font df) {

    setUIFontSize(df.getSize());
    final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys();
    while (keys.hasMoreElements()) {
        final Object key = keys.nextElement();
        final Object value = UIManager.get(key);
        if (value instanceof Font) {
            final Font ifont = (Font) value;
            final Font ofont = new FontUIResource(df.getName(), ifont.getStyle(), df.getSize());
            UIManager.put(key, ofont);
        }
    }
}

From source file:Main.java

public static String getHTMLFontStyle(Font font) {
    StringBuffer out = new StringBuffer();
    out.append("font-size: " + font.getSize() + "px; ");
    out.append("font-family: " + font.getSize() + "; ");
    if (font.isItalic())
        out.append("font-style: italic; ");
    if (font.isBold())
        out.append("font-weight: bold; ");
    return out.toString();
}

From source file:Main.java

/**
 * Changes font size of the specified component.
 *
 * @param component component to modify//from   w w  w . j a v a2 s. c  om
 * @param change    font size change amount
 * @param <C>       component type
 * @return modified component
 */
public static <C extends Component> C changeFontSize(final C component, final int change) {
    if (component != null && component.getFont() != null) {
        final Font font = component.getFont();
        component.setFont(font.deriveFont((float) font.getSize() + change));
    }
    return component;
}

From source file:Main.java

/**
 * Made font bold for the specified component
 *
 * @param comp swing component/*from w  w w .ja  v  a2s  . c  o m*/
 * @return component itself
 */
public static <T extends JComponent> T boldify(T comp) {
    Font font = comp.getFont();
    Font boldFont = new Font(font.getFontName(), Font.BOLD, font.getSize());
    comp.setFont(boldFont);
    return comp;
}

From source file:Main.java

/**
 * Sets component font name.//from w w w  . j  ava 2 s .  co m
 *
 * @param component component font name
 * @param fontName  new font name
 * @param <C>       component type
 * @return modified component
 */
public static <C extends Component> C setFontName(final C component, final String fontName) {
    if (component != null && component.getFont() != null) {
        final Font oldFont = component.getFont();
        component.setFont(new Font(fontName, oldFont.getStyle(), oldFont.getSize()));
    }
    return component;
}

From source file:Main.java

/**
 * Sets the font used for HTML displays to the specified font. Components
 * that display HTML do not necessarily honor font properties, since the
 * HTML document can override these values. Calling {@code setHtmlFont}
 * after the data is set will force the HTML display to use the font
 * specified to this method./*from  ww  w .ja  v a2 s  .  c  o  m*/
 * 
 * @param doc
 *            the HTML document to update
 * @param font
 *            the font to use
 * @throws NullPointerException
 *             if any parameter is {@code null}
 */
public static void setHtmlFont(HTMLDocument doc, Font font) {
    String stylesheet = String.format(STYLESHEET, font.getName(), font.getSize(), font.getName(),
            font.getSize());

    try {
        doc.getStyleSheet().loadRules(new StringReader(stylesheet), null);
    } catch (IOException e) {
        //this should never happen with our sheet
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

public static Font createBoldFont(Font font) {
    if (font == null) {
        throw new NullPointerException("font == null");
    }//from ww  w.  j  a va2 s. c  o  m
    String fontName = font.getName();
    int fontSize = font.getSize();
    return new Font(fontName, Font.BOLD, fontSize);
}

From source file:Main.java

/** 
 * Returns a string with all fonts used by Swing's UIManager.
 *///from  w  ww. j  a v  a  2s.c  o m
public static String getUIFonts() {

    final StringBuffer fonts = new StringBuffer(128);
    fonts.append("Default font: ");
    fonts.append(getUIFont().toString());
    final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys();
    String lf = System.getProperty("line.separator");
    while (keys.hasMoreElements()) {
        final Object key = keys.nextElement();
        final Object value = UIManager.get(key);
        if (value instanceof Font) {
            final Font ifont = (Font) value;
            fonts.append(lf + key.toString() + " " + ifont.getName() + " " + ifont.getStyle() + " "
                    + ifont.getSize());
        }
    }
    return fonts.toString();
}