jframe添加背景图片
来源:互联网 发布:android手机定位源码 编辑:程序博客网 时间:2024/05/16 09:02
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JFrameBackground {
private JFrame frame = new JFrame("背景图片测试");
private JPanel imagePanel;
private ImageIcon background;
public static void main(String[] args) {
new JFrameBackground();
}
public JFrameBackground() {
background = new ImageIcon("003.jpg");// 背景图片
JLabel label = new JLabel(background);// 把背景图片显示在一个标签里面
// 把标签的大小位置设置为图片刚好填充整个面板
label.setBounds(0, 0, background.getIconWidth(),
background.getIconHeight());
// 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
// 内容窗格默认的布局管理器为BorderLayout
imagePanel.setLayout(new FlowLayout());
imagePanel.add(new JButton("测试按钮"));
frame.getLayeredPane().setLayout(null);
// 把背景图片添加到分层窗格的最底层作为背景
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(background.getIconWidth(), background.getIconHeight());
frame.setResizable(false);
frame.setVisible(true);
}
}
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JFrameBackground {
private JFrame frame = new JFrame("背景图片测试");
private JPanel imagePanel;
private ImageIcon background;
public static void main(String[] args) {
new JFrameBackground();
}
public JFrameBackground() {
background = new ImageIcon("003.jpg");// 背景图片
JLabel label = new JLabel(background);// 把背景图片显示在一个标签里面
// 把标签的大小位置设置为图片刚好填充整个面板
label.setBounds(0, 0, background.getIconWidth(),
background.getIconHeight());
// 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
// 内容窗格默认的布局管理器为BorderLayout
imagePanel.setLayout(new FlowLayout());
imagePanel.add(new JButton("测试按钮"));
frame.getLayeredPane().setLayout(null);
// 把背景图片添加到分层窗格的最底层作为背景
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(background.getIconWidth(), background.getIconHeight());
frame.setResizable(false);
frame.setVisible(true);
}
}
- jframe添加背景图片
- 给JFrame上添加背景图片
- Java为JFrame添加背景图片
- 在JFrame上添加背景图片
- java中如何在JFrame中添加背景图片
- Swing-JFrame 浅谈如何在JFrame中添加背景色及背景图片
- JFrame 设置背景图片方法
- JFrame中设置背景图片
- JFrame设置背景图片
- JFrame如何设置背景图片
- 设置JFrame的背景图片
- JFrame放置背景图片
- JFrame中设置背景图片
- JFrame如何设置背景图片
- Java - JFrame 设置背景图片
- jFrame背景图片设置
- JFrame设置背景图片
- java中的图形界面如何在JFrame中添加背景色及背景图片
- 由前序序列和中序序列来重构二叉树
- 《学习OpenCV(中午版)》第3章 练习7
- 本周任务
- 用jsp实现单文件上传(利用开源组件)
- SVN管理公共代码的方法
- jframe添加背景图片
- 《学习OpenCV(中午版)》第3章 练习8
- URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
- jsp标签jsp:setProperty用法
- 深入理解l内核v4l2框架之video for linux 2(一)
- 成为一名PHP专家其实并不难
- java虚拟机内存管理机制(一):JVM内存管理总结
- Eclipse插件安装的三种方法
- 使用Qt Creator远程部署到ARM linux开发板