大侠:
   你好
   怎么给按纽/jlabel上放一张图片/gif动画?
   我用了一些以前讨论过的方法 ,都不行,谁能给我个较详细的例子。
    还有和图片放哪有关系吗?? 不就是设个路径吗???谢谢  急

解决方案 »

  1.   

    JLabel jLabel1 = new JLabel();   
    Icon image = new ImageIcon(getClass().getResource("/***/XXX.gif"));
    jLabel1.setIcon(image);
    jLabel1.setIconTextGap(6);
      

  2.   

    ImageIcon image=new ImageIcon("path");
    JButton b=new JButton(image);
      

  3.   

    按钮上可以直接放图片的,不需要JLabel
      

  4.   


    ImageIcon icon=new ImageIcon("back01.gif");//当前路径
    JLabel l=new JLabel("Hello World!",icon,JLabel.CENTER);
      

  5.   

    public class Frame1 extends JFrame {
      JPanel contentPane;
      JTextField jTextField1 = new JTextField();
      ImageIcon icon=new ImageIcon("D:\\project\\untitled10\\src","12.gif");
    //  Icon image = new ImageIcon(getClass().getResource("D:/project/untitled10/src/12.gif"));
      ImageIcon icon1=new ImageIcon("D:\\project\\untitled10\\src","12.gif");;//当前路径
      JLabel l=new JLabel("Hello World!",icon1,JLabel.CENTER);  JButton jButton1 = new JButton(icon);
      JLabel jLabel1 = new JLabel("Hello World!",icon1,JLabel.CENTER);
    已经被我试得不成人样了,还是搞不定,谁来指点 加一百分单独给大侠  谢谢
      

  6.   

    请点这里,查看详细情况 http://www.lz.net.cn/bbs/X_AdvCom_Get.asp?UserID=7342
      

  7.   

    法一、
    image1 = new ImageIcon("image\\12.gif");//图片在当目录的image文件夹下
    image1 = new ImageIcon("12.gif");//图片在当目录下
    法二、
    image1 = new ImageIcon(path);//path为12.gif的绝对路径
    法三、
    image1 = new ImageIcon(dmis.Frame3.class.getResource("12.gif"));//与此类似。dmis为包名,
    Frame3位类名法四、
    image1 = new ImageIcon("./image/down.gif");//图片在当目录的image文件夹下
    法五、
    不用了吧,会一两种就行了JButton jButton1 = new JButton(image1);
      

  8.   

    Icon image = new ImageIcon(getClass().getResource(iconpath));
    new ImageIcon时不要直接写路径,而应用getClass().getResource(iconpath),
    其中iconpath = “图片的相对路径”,相对您的.java文件可言。