Example usage for javax.swing JLabel JLabel

List of usage examples for javax.swing JLabel JLabel

Introduction

In this page you can find the example usage for javax.swing JLabel JLabel.

Prototype

public JLabel(Icon image) 

Source Link

Document

Creates a JLabel instance with the specified image.

Usage

From source file:Main.java

private static JPanel getPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(new JLabel("Top"), BorderLayout.NORTH);
    panel.add(new JLabel("Center"), BorderLayout.CENTER);
    panel.add(new JLabel("Bottom"), BorderLayout.SOUTH);
    panel.setPreferredSize(new Dimension(400, 300));
    return panel;
}

From source file:Main.java

/** 
 * Creates a <code>JPanel</code> containing the given text placed in the
 * center as the only component./*from   w  ww.  ja  v a  2s. c om*/
 * @param text - the text to put on the panel
 * @return a JPanel containing only the given text
 */
public static JPanel makeTextPanel(String text) {
    JPanel panel = new JPanel(false);
    JLabel filler = new JLabel(text);
    filler.setHorizontalAlignment(SwingConstants.CENTER);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(filler);
    return panel;
}

From source file:Main.java

/**
 *
 * @param strs an array of strings, where each string will be made into a JLabel
 * @return a panel containing a column of JLabels
 *///from   ww w.  ja va  2 s  . c  o  m
public static JPanel getJLabelColumn(String[] strs) {
    JLabel[] labels = new JLabel[strs.length];

    for (int i = 0; i < strs.length; i++) {
        labels[i] = new JLabel(strs[i]);
    }
    return getComponentColumn(labels);
}