JFrame中设置背景图片
2013-08-05 09:06
190 查看
原文地址:JFrame中设置背景图片作者:xiaoy import
javax.swing.*;
import
java.awt.*;
import
java.awt.event.*;
public class
bj
{
private
JFrame
frame
=
new
JFrame("背景图片测试");
private
JPanel
imagePanel
;
private
ImageIcon
background;
public
static
void
main(String[]
args)
{
new
bj();
}
public
bj()
{
background
=
new
ImageIcon("ying.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.setVisible(true);
}
}
javax.swing.*;
import
java.awt.*;
import
java.awt.event.*;
public class
bj
{
private
JFrame
frame
=
new
JFrame("背景图片测试");
private
JPanel
imagePanel
;
private
ImageIcon
background;
public
static
void
main(String[]
args)
{
new
bj();
}
public
bj()
{
background
=
new
ImageIcon("ying.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.setVisible(true);
}
}
相关文章推荐
- 从设置窗体背景图片细谈JFrame
- JFrame 设置背景图片方法
- jFrame设置背景图片的方法
- 设置JFrame的背景图片,实现Jtable 透明
- 为jframe窗口设置背景图片
- 为jframe窗口设置背景图片
- Java - JFrame 设置背景图片
- JFrame设置背景图片
- JFrame如何设置背景图片
- Java 在JFrame中设置背景图片
- java中如何对JFrame进行设置背景颜色和背景图片
- JFrame中设置背景图片
- java如何设置JFrame背景图片
- jFrame背景图片设置
- JFrame如何设置背景图片
- 设置JFrame的背景图片
- JFrame如何设置背景图片
- JFrame设置背景图片的方法
- JFrame设置背景图片
- 为jframe窗口设置背景图片