Java Utililty Methods JLabel Create

List of utility methods to do JLabel Create

Description

The list of methods to do JLabel Create are organized into topic(s).

Method

JPanelcreateCenteredLabel(JLabel label)
create Centered Label
return createLineBoxPanel(Box.createHorizontalGlue(), label, Box.createHorizontalGlue());
JPanelcreateFormPanel(JLabel label, JComponent component)
create Form Panel
JPanel p = new JPanel();
p.setLayout(new BorderLayout(4, 4));
label.setLabelFor(component);
p.add(label, BorderLayout.WEST);
p.add(component, BorderLayout.CENTER);
return p;
JLabelcreateJLabel(Container c, String caption, int x, int y)
This method makes it easy (and also neat) creating a JLabel and adding it to its container class.
FontMetrics fm = c.getFontMetrics(c.getFont());
JLabel lbl = new JLabel(caption);
lbl.setBounds(x, y, fm.stringWidth(caption) + 20, 20);
c.add(lbl);
return lbl;
JLabelcreateJLabel(final String text, final Font font, final Color color)
Creates a label with a specific font and color.
final JLabel result = new JLabel(text);
result.setFont(font);
result.setForeground(color);
return result;
JLabelcreateJLabel(String mlabel)
Create a JLabel but make the font plain instead of super ugly BOLD
JLabel l = new JLabel(mlabel, SwingConstants.LEFT);
setFontType(l, Font.PLAIN);
return l;
JLabelcreateJLabel(String text, Font font)
Creates a label with a specific font.
JLabel result = new JLabel(text);
result.setFont(font);
return result;
JLabelcreateJLabel(String text, Font font)
Creates a label with a specific font.
JLabel result = new JLabel(text);
result.setFont(font);
return result;
JLabelcreateLabel(String name, int x, int y, int width, int height, Font font)
create Label
JLabel label = new JLabel(name);
label.setBounds(x, y, width, height);
if (font != null) {
    label.setFont(font);
return label;
JLabelcreateLabel(String text, Font f)
create Label
JLabel newLab = new JLabel(text);
newLab.setBackground(BG_COLOR);
newLab.setFont(f);
newLab.setForeground(DARK_GREEN_COLOR);
return newLab;
JLabelcreateLabel(String text, Font f, Color c, int position)
create Label
JLabel newLab = new JLabel(text, position);
newLab.setBackground(BG_COLOR);
newLab.setFont(f);
newLab.setForeground(c);
return newLab;