Java BorderFactory create line border

Description

Java BorderFactory create line border

import java.awt.Color;
import java.awt.FlowLayout;

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

public class Main extends JFrame {
  public Main() {
    super("JButton");

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new FlowLayout());
    JLabel nameLabel = new JLabel("Name:");
    JTextField name = new JTextField(20);

    Border border = BorderFactory.createLineBorder(Color.red);
    name.setBorder(border);//from   ww  w  .  j  a va  2s .co  m
    
    getContentPane().add(nameLabel);
    getContentPane().add(name);

  }

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



PreviousNext

Related