|
-
September 28th, 2011, 01:52 PM
#1
window icon
Hi everyone, I need to set an image to the window of my application
I've heard it is this way
frame.setIconImage(new ImageIcon(imgURL).getImage());
but not working, I know setIconImage needs an Image as a parameter, but I don't know how to create it because nowhere it asks for the location of my image
another question:is the window icon (in the upper-left) the same as the task bar icon, or do I have to set two differents sized icons?
thanks!
-
September 29th, 2011, 08:45 AM
#2
Re: window icon
but not working, I know setIconImage needs an Image as a parameter, but I don't know how to create it because nowhere it asks for the location of my image
'imgURL' is a URL that holds the location of your image.
another question:is the window icon (in the upper-left) the same as the task bar icon, or do I have to set two differents sized icons?
The java docs says "Note : Native windowing systems may use different images of differing dimensions to represent a window, depending on the context (e.g. window decoration, window list, taskbar, etc.). They could also use just a single image for all contexts or no image at all."
There is a method setIconImages() to allow you to set images of different sizes if required. On Windows a single image will be scaled to suit the various uses.
-
September 29th, 2011, 10:38 AM
#3
Re: window icon
I changed imgURL with "/resources/img.png" but still not working
-
September 29th, 2011, 11:59 AM
#4
Re: window icon
Are you sure that is the correct relative path for the file?
Trying creating a File object with that path and see if the file exists.
ie:
Code:
System.out.println("file exists = "+new File("/resources/img.png").exists());
-
September 29th, 2011, 01:14 PM
#5
Re: window icon
File file = new File("/resources/minilogo.png");
System.out.println(file.exists());
it throws me false, and the file.getAbsolutePath() is C:\resources\logo.png , but it is in my project folder, also I know \ path separators for windows are not allowed to pass in a String, instead I know to scape them. What can I do?
thanks
-
September 29th, 2011, 01:43 PM
#6
Re: window icon
file.getAbsolutePath() is C:\resources\logo.png
Is that where the file is: C:\resources\
That is where the JVM is looking for it.
Norm
-
September 29th, 2011, 01:51 PM
#7
Re: window icon
how can I change the absolutePath to point my neatBeans project, so anytime I want to get a resource, I just need to put /resources/img?
thanks Norm
-
September 29th, 2011, 01:53 PM
#8
Re: window icon
You could try this. Replace MyIcon.gif with the name of your image file. Place it where you have the rest of your program.
import java.awt.Image;
import java.awt.Toolkit;
Image image = Toolkit.getDefaultToolkit().getImage("MyIcon.gif");
frame.setIconImage(image);
-
September 29th, 2011, 01:53 PM
#9
Re: window icon
Try this to see if you know what the absolute path is:
File file = new File("<Put absolute path here>minilogo.png");
then test if it exists
Norm
-
September 29th, 2011, 03:50 PM
#10
Re: window icon
Try the following code which gets the file using the path relative to the classes location:
Code:
URL logoURL = MyClass.class.getResource("resources/img.png");
ImageIcon appLogo = new ImageIcon(logoURL);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|