Results 1 to 5 of 5
  1. #1
    sirwiggles's Avatar
    sirwiggles is offline Member
    Join Date
    Feb 2009
    Posts
    31
    Rep Power
    0

    Default [SOLVED] Setting a icon

    I'm using blueJ, and i have created a simple application which creates a frame and gives it a title.
    I am wanting to set my own icon to this application, so that the icon can be seen to the right of the frame title, when both onscreen and minimized.

    For example you see the fox icon in any Firefox window when it is both on the screen or minimized.

    Below presents my current code. This code produces no errors. However the default icon (the cup one) appears, rather than the one i specified.
    (Yes, my icon is in the images/ directory.)

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    
    public class IconApplication {
    
    	public static void main(String arg[])
        {
    		//create JFrame with title
    		JFrame frame = new JFrame("Application with a custom icon");
    
            //set frame size too 300, 300
            frame.setSize (500, 150);
            
            //set frame default close operation
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            
            //Cannot change the frames size
            frame.setResizable(false);
            
            //centers the frame 
            frame.setLocationRelativeTo(null);  
    		
    		// Set icon
            Image icon = Toolkit.getDefaultToolkit().getImage("images/icon.ico");
            frame.setIconImage(icon);
    		
    		//set frame visiblitiy to true
            frame.setVisible(true);
    		
    	}
    	
    }
    Any help or guidance would be great, thanks.

  2. #2
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    I think you mean to the left not to the right. I have wondered also how to change it from the java logo. It is possible because when I load Netbeans, for a second its icon is the java logo, but then it switches to the NetBeans logo. I'm not sure how you do it though.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  3. #3
    sirwiggles's Avatar
    sirwiggles is offline Member
    Join Date
    Feb 2009
    Posts
    31
    Rep Power
    0

    Default

    yeah i did, couldnt edit post due to post count and didnt want to double post.

    Surely its possible otherwise every application coded in java would have the same icon.

  4. #4
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Quote Originally Posted by sirwiggles View Post
    yeah i did, couldnt edit post due to post count and didnt want to double post.
    oh
    Quote Originally Posted by sirwiggles View Post
    Surely its possible otherwise every application coded in java would have the same icon.
    Yeah, I didn't mean that I thought is wasn't possible, I just meant I knew for sure it was.. even though its obvious it would have to be anyway.... never mind.
    -MK12
    EDIT: Other senior members or mods: How come I'm a senior member now? Does it just mean I exceeded a certain amount of posts?
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  5. #5
    sirwiggles's Avatar
    sirwiggles is offline Member
    Join Date
    Feb 2009
    Posts
    31
    Rep Power
    0

    Default

    Solution: For some reason java doesnt like the .ico format, i changed it too a gif and it worked.
    Guessing the reason for this is because the complier doesn't see .ico as an image object, but does not throw an exception.

Similar Threads

  1. Applet Icon
    By arimakidd in forum Java Applets
    Replies: 4
    Last Post: 04-30-2009, 05:05 AM
  2. Problem in setting icon for JFrame!
    By pranav13 in forum AWT / Swing
    Replies: 8
    Last Post: 11-04-2008, 06:24 AM
  3. set.Icon
    By safiya in forum NetBeans
    Replies: 2
    Last Post: 10-17-2008, 07:46 PM
  4. icon
    By amith in forum AWT / Swing
    Replies: 1
    Last Post: 05-16-2008, 08:34 PM
  5. To add an icon to my project
    By Albert in forum AWT / Swing
    Replies: 1
    Last Post: 07-13-2007, 04:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •