JAVA swing中JPanel如何实现分组框的效果以及设置边框颜色 分类: Java Game 2014-08-16 12:21 198人阅读 评论(0) 收藏

时间:2023-04-22 19:07:26
代码如下:

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();
} }

转载于:http://www.cnblogs.com/tianguook/archive/2012/03/20/2408306.html