lz 你好
使用setBorder这个方法 设置边框
然后添加带有文字的LineBorder
具体实现如下:(给lz一个完整的例子)
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
public class Test extends JFrame{
private JPanel panel;
private JLabel label;
public Test(){
//标签的icon请设置自己电脑本地的图片
label = new JLabel(new ImageIcon("qq.jpg"));
//基本的LineBorder
LineBorder lb = new LineBorder(Color.BLACK, 1, false);
panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
panel.add(label);
panel.setBounds(100,50,300,300);
//设置带有文字的LineBorder
panel.setBorder(BorderFactory.createTitledBorder(lb, "欢迎进入", TitledBorder.LEFT, TitledBorder.TOP));
setLayout(null);
getContentPane().add(panel);
setSize(500,500);
setLocationRelativeTo(null);
setDefaultCloseOperation(3);
setVisible(true);
}
public static void main (String[] args) {
new Test();
}
}
运行效果:
ps:
图片的位置和名称,lz自己设定为本地就行了
希望能帮助你哈
这是一个标题边框,我给你个例子你看看吧.
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class JJJ extends JFrame {
JJJ(){
super("小男孩超市管理系统2.50");
JPanel p = new JPanel();
p.setBorder (BorderFactory.createTitledBorder ("欢迎进入"));
add (p);
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new JJJ();
}
}
JLabel l = new JLabel("欢迎进入")