JDesktopPane改变窗体大小时背景图片自动适应窗体大小
来源:互联网 发布:外文数据库免费入口 编辑:程序博客网 时间:2024/05/16 11:17
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author ZRL
* @date 2017/11/6
*/
public class AddBackgroundToJDesktopPane extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
AddBackgroundToJDesktopPane desktopPane = new AddBackgroundToJDesktopPane();
desktopPane.setVisible(true);
}
public AddBackgroundToJDesktopPane() {
super();
setTitle("桌面面板添加背景图片示例");
setBounds(100, 100, 700, 400);
final JDesktopPane desktopPane = new JDesktopPane();
ImageIcon icon = new ImageIcon(resource);
//压缩背景图片,使其适应窗口大小
icon.setImage(icon.getImage().getScaledInstance(this.getWidth(), this.getHeight(), Image.SCALE_DEFAULT));
backgroundLabel.setIcon(icon);
backgroundLabel.setBounds(0, 0, this.getWidth(), this.getHeight());
desktopPane.add(backgroundLabel, new Integer(Integer.MIN_VALUE));
//当改变窗口大小时,自动调整背景图片大小
getContentPane().addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
int width = e.getComponent().getWidth();
int heigth = e.getComponent().getHeight();
icon.setImage(icon.getImage().getScaledInstance(width,heigth, Image.SCALE_DEFAULT));
backgroundLabel.setBounds(0, 0,width,heigth);
}
});
}
}
import java.awt.Image;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author ZRL
* @date 2017/11/6
*/
public class AddBackgroundToJDesktopPane extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
AddBackgroundToJDesktopPane desktopPane = new AddBackgroundToJDesktopPane();
desktopPane.setVisible(true);
}
public AddBackgroundToJDesktopPane() {
super();
setTitle("桌面面板添加背景图片示例");
setBounds(100, 100, 700, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JDesktopPane desktopPane = new JDesktopPane();
getContentPane().add(desktopPane, BorderLayout.CENTER);
final JLabel backgroundLabel = new JLabel();
//自己选择一张背景图片,需要放在src目录下
URL resource = this.getClass().getResource("/back.jpg");ImageIcon icon = new ImageIcon(resource);
//压缩背景图片,使其适应窗口大小
icon.setImage(icon.getImage().getScaledInstance(this.getWidth(), this.getHeight(), Image.SCALE_DEFAULT));
backgroundLabel.setIcon(icon);
backgroundLabel.setBounds(0, 0, this.getWidth(), this.getHeight());
desktopPane.add(backgroundLabel, new Integer(Integer.MIN_VALUE));
//当改变窗口大小时,自动调整背景图片大小
getContentPane().addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
int width = e.getComponent().getWidth();
int heigth = e.getComponent().getHeight();
icon.setImage(icon.getImage().getScaledInstance(width,heigth, Image.SCALE_DEFAULT));
backgroundLabel.setBounds(0, 0,width,heigth);
}
});
}
}
阅读全文
0 0
- JDesktopPane改变窗体大小时背景图片自动适应窗体大小
- 设置winform窗体背景图片自动适应窗体大小
- C# WinForm控件随窗体大小改变自动适应改变
- C# WinForm控件随窗体大小改变自动适应改变
- C# 改变窗体大小时背景图片会闪烁解决办法
- 如何实现控件随窗体大小的改变而自动适应其改变
- 如何实现控件随窗体大小的改变而自动适应其改变
- 当窗体改变大小时控件大小随之改变(使用函数)
- C#如何实现控件随窗体大小的改变而自动适应
- Ext3.2.2 表格随窗口改变动态适应窗体大小
- 在.Net的WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- 在.Net的WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- c#,VC++ 在WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- 巨海集团商学院双十一特惠大礼包,给您一个增值的自己
- PreparedStatement 使用like 模糊查询
- 健康类App原型制作分享-Pillow
- Qt实例-UCF数据标注
- OpenCV3.3-Python3.6.2中KNN使用举例
- JDesktopPane改变窗体大小时背景图片自动适应窗体大小
- Redhat Linux 7.3网络服务无法启动解决办法
- checkbox js验证只有一个可选
- RNG类
- 检查文件是否存在于远程服务器上
- Tensorflow-Mask RCNN
- 常用开发工具介绍
- iOS开发实现HTTPS之 cer 文件的使用
- Windows上使用SecureCRT软件连接Linux终端 — 解决问题;The remote system refused the connection