LineBorder Class : LineBorder « Swing « Java Tutorial






The line border is a single-color line of a user-defined thickness that surrounds a component.

public LineBorder(Color color)
Border lineBorder = new LineBorder (Color.RED);

public LineBorder(Color color, int thickness)
Border lineBorder = new LineBorder (Color.RED, 5);

public LineBorder (Color color, int thickness, boolean roundedCorners)
Border lineBorder = new LineBorder (Color.RED, 5, true);

public static Border createBlackLineBorder()
Border blackLine = LineBorder.createBlackLineBorder();
public static Border createGrayLineBorder()
Border grayLine = LineBorder.createGrayLineBorder();

public static Border createLineBorder(Color color)
Border lineBorder = BorderFactory.createLineBorder(Color.RED);

public static Border createLineBorder(Color color, int thickness)
Border lineBorder = BorderFactory.createLineBorder(Color.RED, 5);
import java.awt.Color;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

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

public class Main extends JFrame {

  public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel("Some label text");
    label.setBorder(BorderFactory.createLineBorder(Color.green));
    label.setFont(new Font("Serif", Font.ITALIC, 16));

    getContentPane().add(label);
    pack();
    setVisible(true);
  }

  public static void main(String arg[]) {
    new Main();
  }
}








14.100.LineBorder
14.100.1.LineBorder Class
14.100.2.LineBorder: color and widthLineBorder: color and width
14.100.3.Creating and Setting a line Border from BorderFactory