Java JLabel set preferred size

Description

Java JLabel set preferred size

import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main extends JFrame {

  public Main() {
    super("Link JLabel with JTextField");

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JLabel nameLabel = new JLabel("Java demo from demo2s.com.");

    nameLabel.setPreferredSize(new Dimension(175, 100));
    add(nameLabel);//from w w w  .  j a v a  2s  . com

  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related