请问:如何将控件的背景设置为一张图片或者如何用一个控件将图片导入Eclipse
我在项目下面建立了一个res文件夹,并将图片放在这里,可是调用时却不行,为什么?

解决方案 »

  1.   

    可以用这个方法:
    aboutlabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/about.jpg")))
    不过这个about.jpg是在src文件夹里的
      

  2.   

    灵活运用标签
    private JPanel getJPanel() {
    if (jPanel == null) {
    ImageIcon ico=new ImageIcon("00.gif");
    jLabel9 = new JLabel(ico);
    jLabel9.setBounds(new Rectangle(-5, 0, 990, 572));
    jLabel9.setText("");
    }
    图片copy到项目里,刷新项目 在你的jar系统库里能显示出图片来