Java JLabel set line border

Description

Java JLabel set line border

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;

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.");
    Border border = BorderFactory.createLineBorder(Color.red);

    nameLabel.setBorder(border);//from ww  w .  j  av a 2s  .  co m

    add(nameLabel);

  }

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



PreviousNext

Related