what's an easy way to set up an icon for a program in swing?

Discussion in 'OT Technology' started by D1G1T4L, Jun 19, 2003.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    you know when you minimize a program, it has an icon in the taskbar, so i was wondering how to change that icon.

    i know there is a setIconImage(); for Frame
    but the problem is that it only accepts java.awt type
    so if i do
    Code:
    Icon logo = new ImageIcon("logo.gif");
    setIconImage(logo);
    
    it won't work

    the only way i found is
    Code:
    Toolkit tkit=Toolkit.getDefaultToolkit();
    Image icon = tkit.getImage(ClassLoader.getSystemClassLoader().getResource("images\\icon.gif"));
    setIconImage(icon); 
    
    is there an easier way than to use Toolkit class?
     
  2. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    i am also wondering how come they didnt make a setIconImage for JFrame :wtc:
     
  3. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    never mind i got it

    Code:
    ImageIcon logo = new ImageIcon("logo.gif");
    setIconImage(logo.getImage());
    
     
  4. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    I don't know why, but I always thought ImageIcon was abstract. Thanks for the solution, I'm sure I'll want to use this later. ;)
     

Share This Page