日期:2014-05-20 浏览次数:20736 次
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class TestJDesktopPane
{
JFrame frame;
JDesktopPane desktopPane;
JLabel backLabel;
ImageIcon icon;
public TestJDesktopPane()
{
frame = new JFrame("主面板");
desktopPane = new JDesktopPane(); //虚拟桌面
backLabel = new JLabel(); //背景图标
icon = new ImageIcon("e:/Tulips.jpg");
frame.setBounds(0,0,800,600);
backLabel.setIcon(icon);
frame.addComponentListener(new ComponentAdapter(){ //为主面板添加窗口监听器
@Override
public void componentResized(ComponentEvent e)
{
//System.out.println(frame.getWidth());
backLabel.setSize(frame.getWidth(),frame.getHeight());
System.out.println("-----------");
System.out.println(backLabel.getWidth() + " " +icon.getIconWidth());
}
});
desktopPane.add(backLabel,new Integer(Integer.MIN_VALUE));
frame.add(desktopPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args)
{
new TestJDesktopPane();
}
}