Java JComponent Color createLabel(final String label, final int alignment, final Color background, final Color foreground)

Here you can find the source of createLabel(final String label, final int alignment, final Color background, final Color foreground)

Description

Creates a label with the given properties already preset.

License

Open Source License

Parameter

Parameter Description
label the string to be displayed by the <code>JLabel</code>
alignment the horizontal alignment of the <code>JLabel</code>
background the background color to be used for the <code>JLabel</code>
foreground the foreground color to be used for the <code>JLabel</code>

Declaration


public static JLabel createLabel(final String label,
        final int alignment, final Color background,
        final Color foreground) 

Method Source Code

//package com.java2s;
import java.awt.Color;

import javax.swing.JLabel;

public class Main {
    /**//w ww .  j  a va 2 s .  co  m
     * Creates a label with the given properties already preset. The label will also, by default, be opaque, so that the
     * background color specified will be able to show through.
     *
     * @param label the string to be displayed by the <code>JLabel</code>
     * @param alignment the horizontal alignment of the <code>JLabel</code>
     * @param background the background color to be used for the <code>JLabel</code>
     * @param foreground the foreground color to be used for the <code>JLabel</code>
     */

    public static JLabel createLabel(final String label,
            final int alignment, final Color background,
            final Color foreground) {
        JLabel presetLabel = new JLabel(label, alignment);
        presetLabel.setForeground(foreground);
        presetLabel.setBackground(background);
        presetLabel.setOpaque(true);
        return presetLabel;
    }
}

Related

  1. convertHtmlColorNameToColor(String htmlColorName)
  2. createColorChooser(Component component)
  3. createDisabledTextComponent (String text, Color color, boolean textField)
  4. createDisabledTextField (String text, Color color)
  5. createHorizontalLine(Color background)
  6. createLabel(JComponent parent, String text, Color color)
  7. createTextArea(String str, Color color)
  8. findPanel(JColorChooser chooser, String name)
  9. fixOsxColorChooser(JColorChooser chooser)