JDesktopPane设置背景图片的方法

 

private ImageIcon backgroundImg;		 
/**
         * 加载背景图片
         */
        try {
			backgroundImg = ImageIO.read(new FileInputStream("banner03.jpg"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
desktopPane = new JDesktopPane(){
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			protected void paintChildren(java.awt.Graphics g) {
				
				 if   (backgroundImg   !=   null) 
			      { 
			               g.drawImage(backgroundImg,   0,   0,   getWidth(),   getHeight(),   this); 
			                                } 
			                              super.paintChildren(g); 

			};
		};
jframe.setExtendedState(JFrame.MAXIMIZED_BOTH);//全屏最大化

 如上JDesktopPane设置背景图片的方法

 

你可能感兴趣的:(Desktop)