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"));//基本的LineBorderLineBorder 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);//设置带有文字的LineBorderpanel.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自己设定为本地就行了希望能帮助你哈
阅读全文 >