为何设置JFrame背景失败

younglee2013 younglee2013 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:
import java.awt.*;
import javax.swing.*;
public class mFramewithPictureAsBack {
public mFramewithPictureAsBack() {}
public static void main(String[] args) {
JFrame frame = new JFrame("背景图设置");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon img = new ImageIcon("images//a4.png");
JLabel label = new JLabel(img);
label.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
Container con = frame.getContentPane();
con.setLayout(new GridLayout(1, 1));
JButton btn = new JButton("按钮");
con.add(btn);
((JPanel)con).setOpaque(false);
frame.setSize(500, 300);
frame.setVisible(true);
}
}
...全文
评论 1
收藏 已收藏
分享
返回顶部
younglee2013
非技术区 23,404 成员 70,506 内容