Java Swing Font addLabel(Container component, String text, Icon icon, int horizontalAlignment, Font font)

Here you can find the source of addLabel(Container component, String text, Icon icon, int horizontalAlignment, Font font)

Description

Add a new label to a given component

License

Open Source License

Parameter

Parameter Description
component Component to add the label to
text Label's text
icon Label's icon
horizontalAlignment Label's horizontal alignment (e.g. JLabel.LEFT)
font Label's font

Return

Created label

Declaration

public static JLabel addLabel(Container component, String text, Icon icon, int horizontalAlignment, Font font) 

Method Source Code


//package com.java2s;
/*//from ww w. ja v  a  2  s .c  om
 * Copyright 2007-2013 VTT Biotechnology
 * This file is part of Guineu.
 *
 * Guineu is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * Guineu is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Guineu; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */

import java.awt.Container;

import java.awt.Font;

import javax.swing.Icon;

import javax.swing.JLabel;

public class Main {
    /**
     * Add a new label to a given component
     *
     * @param component Component to add the label to
     * @param text Label's text
     * @return Created label
     */
    public static JLabel addLabel(Container component, String text) {
        return addLabel(component, text, null, JLabel.LEFT, null);
    }

    /**
     * Add a new label to a given component
     *
     * @param component Component to add the label to
     * @param text Label's text
     * @param horizontalAlignment Label's horizontal alignment (e.g.
     *            JLabel.LEFT)
     * @return Created label
     */
    public static JLabel addLabel(Container component, String text, int horizontalAlignment) {
        return addLabel(component, text, null, horizontalAlignment, null);
    }

    /**
     * Add a new label to a given component
     *
     * @param component Component to add the label to
     * @param text Label's text
     * @param horizontalAlignment Label's horizontal alignment (e.g.
     *            JLabel.LEFT)
     * @param font Label's font
     * @return Created label
     */
    public static JLabel addLabel(Container component, String text, int horizontalAlignment, Font font) {
        return addLabel(component, text, null, horizontalAlignment, font);
    }

    /**
     * Add a new label to a given component
     *
     * @param component Component to add the label to
     * @param text Label's text
     * @param icon Label's icon
     * @param horizontalAlignment Label's horizontal alignment (e.g.
     *            JLabel.LEFT)
     * @param font Label's font
     * @return Created label
     */
    public static JLabel addLabel(Container component, String text, Icon icon, int horizontalAlignment, Font font) {
        JLabel label = new JLabel(text, icon, horizontalAlignment);
        if (component != null) {
            component.add(label);
        }
        if (font != null) {
            label.setFont(font);
        }
        return label;
    }
}

Related

  1. applyComponentFont(JComponent c)
  2. applyFont(JPanel p)
  3. applyProperties(final Component comp, final Color colBack, final Color colFore, final Font font)
  4. autoAwesomeLookAndFeel(String fontName, Map defaults)