您的位置:首页 > 其它

swing中JPanel如何实现分组框的效果以及设置边框颜色

2012-03-20 17:51 661 查看
代码如下:

import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class JFrameBackground extends JFrame {
public JFrameBackground(){
this.setTitle("我的swing界面");
this.setLayout(new FlowLayout());
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(BorderFactory.createTitledBorder("分组框")); //设置面板边框,实现分组框的效果,此句代码为关键代码

buttonPanel.setBorder(BorderFactory.createLineBorder(Color.red));//设置面板边框颜色
JButton button = new JButton("我的按钮");
buttonPanel.add(button);
this.setSize(300, 300);
this.getContentPane().add(buttonPanel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}

public static void main(String[] args) {
new JFrameBackground();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐