import javax.swing.*;
import java.awt.Color;JTextField text = new JTextField("Demo");
text.setBorder(BorderFactory.creatLineBorder(Color.red , 2));
还有很多种边框的类型,有一个包javax.swing.border,BorderFactory是产生边框的工厂。