Java Swing How to - Change JLabel size








Question

We would like to know how to change JLabel size.

Answer

//from ww  w .j  a va  2 s .c o  m
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Main {
  public static void main(String[] args) {
    
    JLabel label = new JLabel("java2s.com", JLabel.LEFT);
    label.setPreferredSize(new Dimension(150, 100));
    
    JOptionPane.showMessageDialog(null, label);
    
  }
}