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, int horizontalAlignment) 

Source Link

Document

Creates a JLabel instance with the specified image and horizontal alignment.

Usage

From source file:Main.java

public static void main(String[] args) {

    JLabel label = new JLabel("java2s.com", JLabel.LEFT);
    label.setPreferredSize(new Dimension(150, 100));

    JOptionPane.showMessageDialog(null, label);

}

From source file:Main.java

public static void main(String[] args) {

    JLabel label = new JLabel("Full Name :", JLabel.LEFT);

    label.setOpaque(true);// ww  w  . ja  v a2  s . co m
    label.setForeground(new Color(150, 150, 25));
    label.setBackground(new Color(50, 50, 25));

    JOptionPane.showMessageDialog(null, label);

}

From source file:Main.java

public static void main(String[] args) {

    JLabel label = new JLabel("java2s.com", JLabel.LEFT);
    Border border = BorderFactory.createLineBorder(Color.BLACK);
    label.setBorder(border);//from   w ww . j a  va 2  s. c o m

    JOptionPane.showMessageDialog(null, label);

}

From source file:SimpleSplashScreen.java

public static void main(String[] arg) {
    JWindow jwin = new JWindow();
    jwin.getContentPane().add(new JLabel("Loading ZIP/JAR Manager...", SwingConstants.CENTER));
    jwin.setBounds(200, 200, 200, 100);//from   w  w  w  .  j  a  v a2s .c  o  m
    jwin.setVisible(true);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    jwin.setVisible(false);
    jwin.dispose();

}

From source file:Main.java

public static void main(String args[]) {
    JWindow window = new JWindow();
    window.getContentPane().add(new JLabel("Loading", SwingConstants.CENTER));
    window.setBounds(500, 150, 300, 200);
    window.setVisible(true);//  ww w .j  a  v  a  2 s .  c om
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
    window.setVisible(false);
    JFrame frame = new JFrame();
    frame.add(new JLabel("Welcome Swing application..."));
    frame.setVisible(true);
    frame.setSize(300, 200);
    window.dispose();
}

From source file:JColorChooserWithCustomPreviewPanel.java

public static void main(String[] a) {

    final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER);
    previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));
    previewLabel.setSize(previewLabel.getPreferredSize());
    previewLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0));

    JColorChooser colorChooser = new JColorChooser();
    colorChooser.setPreviewPanel(previewLabel);

    JDialog d = colorChooser.createDialog(null, "", true, colorChooser, null, null);

    d.setVisible(true);/* w w  w.  j a  v a2s  . c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    JLabel label1 = new JLabel("BottomRight", SwingConstants.RIGHT);
    JLabel label2 = new JLabel("CenterLeft", SwingConstants.LEFT);
    JLabel label3 = new JLabel("TopCenter", SwingConstants.CENTER);
    label1.setVerticalAlignment(SwingConstants.BOTTOM);
    label2.setVerticalAlignment(SwingConstants.CENTER);
    label3.setVerticalAlignment(SwingConstants.TOP);

    label1.setBorder(BorderFactory.createLineBorder(Color.black));
    label2.setBorder(BorderFactory.createLineBorder(Color.black));
    label3.setBorder(BorderFactory.createLineBorder(Color.black));

    JFrame frame = new JFrame("AlignmentExample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel(new GridLayout(3, 1, 8, 8));
    p.add(label1);//from  ww  w.  j  a  v  a2s .  com
    p.add(label2);
    p.add(label3);
    p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    frame.setContentPane(p);
    frame.setSize(200, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTabbedPane tabbedPane = new JTabbedPane();
    for (int i = 0; i < 5; i++) {
        tabbedPane.add("Tab " + i, new JLabel("Label " + i, SwingConstants.CENTER));
    }/*from w  w  w. j ava 2s . co m*/

    tabbedPane.getModel().addChangeListener(e -> {
        JLabel label = (JLabel) tabbedPane.getSelectedComponent();
        System.out.println(label.getText());
    });

    tabbedPane.setPreferredSize(new Dimension(500, 300));

    JFrame frame = new JFrame();
    frame.getContentPane().add(tabbedPane);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) throws Exception {
    String fileName = "BigFile.txt";
    FileInputStream fis = new FileInputStream(fileName);
    JLabel filenameLabel = new JLabel(fileName, JLabel.RIGHT);
    Object message[] = { "Reading:", filenameLabel };
    ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, message, fis);
    InputStreamReader isr = new InputStreamReader(pmis);
    BufferedReader br = new BufferedReader(isr);
    String line;// w w  w .  j  av a 2s. c  o  m
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br.close();
}

From source file:Main.java

public static void main(String[] args) {
    JLabel l;/*from  w  ww  . j  a v  a 2s  . c om*/
    JTextField t;
    JButton b;
    JFrame f = new JFrame("Text Accelerator");

    f.add(l = new JLabel("Name:", SwingConstants.RIGHT));
    l.setDisplayedMnemonic('n');
    f.add(l = new JLabel("House/Street:", SwingConstants.RIGHT));
    l.setDisplayedMnemonic('h');
    f.add(l = new JLabel("City:", SwingConstants.RIGHT));
    l.setDisplayedMnemonic('c');
    f.add(l = new JLabel("State/County:", SwingConstants.RIGHT));
    l.setDisplayedMnemonic('s');
    f.add(l = new JLabel("Zip/Post code:", SwingConstants.RIGHT));
    l.setDisplayedMnemonic('z');
    f.add(l = new JLabel("Telephone:", SwingConstants.RIGHT));
    l.setDisplayedMnemonic('t');
    f.add(b = new JButton("Clear"));
    b.setMnemonic('l');

    f.add(t = new JTextField(35));
    t.setFocusAccelerator('n');
    f.add(t = new JTextField(35));
    t.setFocusAccelerator('h');
    f.add(t = new JTextField(35));
    t.setFocusAccelerator('c');
    f.add(t = new JTextField(35));
    t.setFocusAccelerator('s');
    f.add(t = new JTextField(35));
    t.setFocusAccelerator('z');
    f.add(t = new JTextField(35));
    t.setFocusAccelerator('t');
    f.add(b = new JButton("OK"));
    b.setMnemonic('o');

    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}