in JFrame desktop = new JDesktopPane(){ public void paintChildren(Graphics g) { if (backgroundImg != null) { g.drawImage(backgroundImg, 0, 0, getWidth(), getHeight(), this); } super.paintChildren(g); } };
contentpane.add(desktop,BorderLayout.CENTER);
在desktop上放一个label // Here, we load a background image for our desktop. protected void loadBackgroundImage( ) { ImageIcon icon = new ImageIcon("matterhorn.gif"); JLabel l = new JLabel(icon); l.setBounds(0,0,icon.getIconWidth( ),icon.getIconHeight( )); // Place the image in the lowest possible layer so nothing can ever be painted // under it. desk.add(l, new Integer(Integer.MIN_VALUE)); }
public void paintChildren(Graphics g)
{
if (backgroundImg != null)
{
g.drawImage(backgroundImg, 0, 0, getWidth(), getHeight(), this);
}
super.paintChildren(g);
} };
contentpane.add(desktop,BorderLayout.CENTER);
// Here, we load a background image for our desktop.
protected void loadBackgroundImage( ) {
ImageIcon icon = new ImageIcon("matterhorn.gif");
JLabel l = new JLabel(icon);
l.setBounds(0,0,icon.getIconWidth( ),icon.getIconHeight( )); // Place the image in the lowest possible layer so nothing can ever be painted
// under it.
desk.add(l, new Integer(Integer.MIN_VALUE));
}
我用的是 stevenmo(凯) 的方法...3Q..