用eclipse写的一个jframe在运行的时候可以显示背图片,但是预览的时候没有显示背景图片
我用label放置背景图片,在运行的时候可以看到背景图片,但是在进行预览的时候没有显示背景图片。
而且,在我自己的计算机中运行的时候可以正常运行,背景图片也可以看到。但是有那个别人的计算机的时候就不能显示背景图片了。
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HomeFrame frame = new HomeFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public HomeFrame() {
initComponents();
}
public void initComponents(){
this.setResizable(false);
setTitle("\u57FA\u4E8E\u5185\u5BB9\u7684\u6587\u4EF6\u5206\u7C7B\u7CFB\u7EDF\r\n");
setForeground(Color.BLUE);
setBackground(Color.BLUE);
setBounds(100, 100, 604, 438);
contentPane = new JPanel();
//setBackgroundImage=
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new GridLayout(1, 0, 0, 0));
JPanel mainpanel = new JPanel();
contentPane.add(mainpanel);
contentPane.setOpaque(false);
mainpanel.setOpaque(false);
mainpanel.setLayout(new BorderLayout(0, 0));
ImageIcon backgroundimage=new ImageIcon("backgroundimage.jpg");
JLabel imagelabel=new JLabel(backgroundimage);
imagelabel.setBounds(0,0, backgroundimage.getIconWidth(), backgroundimage.getIconHeight());
//contentPane.add(imagelabel,new Integer(Integer.MIN_VALUE));
this.getLayeredPane().add(imagelabel,new Integer(Integer.MIN_VALUE));
}
}
图片的大小问题,试着把图片变小一点吧。