Recent changes Random page
GAMING
Technology
 
Gaming
Entertainment
Science Fiction
Biggest wikis
Hobbies
Music
See more...

Forum:Icons in menu?

From Planet JFX

Jump to: navigation, search
 
Forums: Index > Help desk > Icons in menu?


Hey all!

I was wondering if anyone has figured out how to add an icon to a menu item. I found this:

 MenuItem {
   icon: Image {url: "url" }
 }

but... I can't seem to access local images with this! Any ideas?

To get the url for images on the local classpath, try:
Thread.currentThread().getContextClassLoader().getResource( "path/to/my-image.png" ).toString();
and give that to the url: attribute. Pforhan 19:15, 22 October 2007 (UTC)


Thanks, but I just solved this problem:
MenuItem {	icon: Image {url: "{__DIR__}/path/to/image.png"	}}
It's a bit simpler this way :)
Yes, you can do that, but you run into the standard deployment problem: As soon as you put that in a JAR or on a remote site, file access will fail and you'll be left with nonfunctional code. This is the same issue as using java.io.File to load resources instead of the class loader.
My code above is a little wonky because there's no quick-and-easy access to a classloader like there is for java class files. That is subject to change with the JFX compiler, and some language changes have been discussed. -- Pforhan 12:42, 23 October 2007 (UTC)




Try the following instead:
MenuItem {
    icon: Image {
	url: "file:relative/path/to/image.png"
    }
}

You'll also want to verify whether the MenuItem will accept the PNG format, versus GIF or JPEG. --Rcasey 21:12, 23 October 2007 (UTC)