JFrame的背景图片 [英] JFrame background image
本文介绍了JFrame的背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建一个图形用户界面,虽然是一个简单的,我希望有一个背景图像(2048×2048)填满整个窗口和一个正方形的左上角,其中偶尔的64×64的图像可以被加载。在此先感谢任何人谁帮助了:)
编辑:我已经知道如何使JFrame的一组大小,其图像加载我需要帮助
I am creating a GUI, albeit a simple one, and I want to have a background image (2048 X 2048) fill up the whole window and a square to the left top corner where the occasional 64 X 64 image can be loaded. Thanks in advance to anyone who helps out :) I already know how to make the JFrame a set size, its the image loading I need help with.
推荐答案
这是在一个JFrame添加背景图片简单的例子
this is simple example for adding the background image in a jframe
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class BackgroundImageJFrame extends JFrame
{
JButton b1;
JLabel l1;
public BackgroundImageJFrame()
{
setTitle("Background Color for JFrame");
setSize(400,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
/*
One way
-----------------
setLayout(new BorderLayout());
JLabel background=new JLabel(new ImageIcon("C:\\Users\\Computer\\Downloads\\colorful design.png"));
add(background);
background.setLayout(new FlowLayout());
l1=new JLabel("Here is a button");
b1=new JButton("I am a button");
background.add(l1);
background.add(b1);
*/
// Another way
setLayout(new BorderLayout());
setContentPane(new JLabel(new ImageIcon("C:\\Users\\Computer\\Downloads\\colorful design.png")));
setLayout(new FlowLayout());
l1=new JLabel("Here is a button");
b1=new JButton("I am a button");
add(l1);
add(b1);
// Just for refresh :) Not optional!
setSize(399,399);
setSize(400,400);
}
public static void main(String args[])
{
new BackgroundImageJFrame();
}
}
- 点击<一个href=\"http://java-demos.blogspot.in/2012/09/setting-background-image-in-jframe.html#sthash.UbBXgFpM.dpuf\">here更多资讯
- click here for more info
这篇关于JFrame的背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文