當前位置:首頁 » 背景圖片 » java載入背景圖片
擴展閱讀
手機好多圖片 2025-02-02 09:48:56
日本哪個牙膏最好圖片 2025-02-02 09:46:41

java載入背景圖片

發布時間: 2023-08-06 21:37:47

⑴ 如何在java的窗口中添加背景圖片

可以新建個面板,在面板里放入帶圖片的JLabel,填鄭晌滿面板即可。
JPanel jp = new JPanel(); //新扮悔建面板
jp.setLayout(new FlowLayout()); //設置面板布局
ImageIcon ii=new ImageIcon(getClass().getResource("/Picture/i.jpg"));
JLabel uppicture=new JLabel(ii); //往面板里加廳叢正入JLabel
this.setVisible(true);

⑵ Java怎麼添加背景圖片

這是我以前的一個小代碼你可以看看
public class demo_9 extends JFrame {
JSplitPane jsp = null;
JList jlist;
JLabel jlabel;

public static void main(String[] args) {
demo_9 a = new demo_9();

}
public demo_9(){
String []words ={"boy","girl"};
JList jlist = new JList(words);
jlabel = new JLabel(new ImageIcon("Image//真三.gif")); //這里就是引入圖片了
//拆分窗格
jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jlist,jlabel);
jsp.setDividerLocation(70);
//設置可以伸縮
jsp.setOneTouchExpandable(true);
this.add(jsp);
this.setTitle("test");
this.setSize(400,300);
this.setLocation(400,200);
this.setVisible(true);
}

}
步驟:首先先在project里新建個文件夾(Folder),然後把你要插入的圖片復制黏貼到這個文件夾裡面。
例如我那個引入的圖片代碼:jlabel = new JLabel(new ImageIcon("Image//真三.gif"));
我new一個folder叫Image,圖片名稱叫"真三.gif"

⑶ 怎麼在Java里添加背景圖片

可以新建個面板,在面板里放入帶圖片的JLabel,填滿面板即可。
JPanel jp = new JPanel(); //新建面板
jp.setLayout(new FlowLayout()); //設置面板布局
ImageIcon ii=new ImageIcon(getClass().getResource("/Picture/i.jpg"));
JLabel uppicture=new JLabel(ii); //往面板里加入JLabel
this.setVisible(true);

⑷ 在java中添加背景圖片

OK,我用你的程序測試了一下,基本幫你解決了,你在這個位置寫上這幾句

exit.addActionListener(newActionListener(){//退出系統監聽

publicvoidactionPerformed(ActionEvente){

setVisible(false);

}

});

/**加入背景圖片的話**/

ImageIconim=newImageIcon("./image/denglujiemian.jpg");

JLabell1=newJLabel(im);

l1.setBounds(0,0,300,200);

deskpane.add(l1);

this.setBounds(200,200,300,200);

setVisible(true);

}

注釋:ImageIconim=newImageIcon("./image/denglujiemian.jpg");

這里的image是需要你自己創的一個包,裡面放你需要的圖片,記住書寫格式"./image/**.jpg"

效果截圖:

⑸ 在java中怎樣添加背景圖片

//不加包,圖片跟類文件在一個目錄,命令行下編譯執行就行了

//如果建工程,圖片放到工程根目錄

importjava.awt.Container;

importjava.awt.FlowLayout;

importjavax.swing.ImageIcon;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JPanel;

{

publicStudent(){

init();

}

privatevoidinit(){

finalContainerc=getContentPane();

finalJLabelimgLabel=newJLabel();

ImageIconimg=newImageIcon(System.getProperty("user.dir")+"\a.png");

imgLabel.setIcon(img);

imgLabel.setBounds(0,0,img.getIconWidth(),img.getIconHeight());

((JPanel)getContentPane()).setOpaque(false);

getLayeredPane().add(imgLabel,newInteger(Integer.MIN_VALUE));

setLayout(newFlowLayout());

setSize(500,500);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

publicstaticvoidmain(String[]args){

newStudent().setVisible(true);

}

}

⑹ java中的swing設計界面時怎麼加上背景圖片。而不覆蓋什麼label等控制項

通過以下方式設置下背景就可以了:

background=newImageIcon("images/backImage.png");

backImage攔碼=newJLabel(background);

backImage.setBounds(0,0,background.getIconWidth(),

background.getIconHeight());

backPanel=(JPanel)this.getContentPane();

backPanel.setOpaque(false);

this.getLayeredPane().setLayout(null);

this.getLayeredPane().add(backImage,簡滾哪newInteger(Integer.MIN_VALUE));

backPanel.setLayout(newBorderLayout());

這樣就可以把圖片備漏放在最下面了,效果圖:

⑺ java窗體如何添加背景圖片