Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to load icons?
How to load icons? [message #630671] Mon, 04 October 2010 14:15 Go to next message
Thomas is currently offline ThomasFriend
Messages: 79
Registered: October 2009
Member
hi, i defined my own icons and i want to use them in my rcp-application in a tree view.

(ProjectStructure)

-xxxProject
--src
--icons
---icons
----myicon.png (this icon)

when i try to load them in:

File f = new File("icons/icons/myicon.png");
if(!f.exists()){
System.out.println("doNotExist");
}
else{
System.out.println("doExist");
}

File f do always not exist. Whats the Relative Path of my icon?

thanks
Re: How to load icons? [message #630703 is a reply to message #630671] Mon, 04 October 2010 15:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mluchian.interpro.qc.ca

Hi,

Assuming you are using Eclipse 3.4, 3.5 or 3.6, you can use
WindowbuilderPro GUI builder that is now part of the open source
community and downloadable for free at:
http://code.google.com/webtoolkit/tools/download-wbpro.html

I does also generates some helper classes (SWTResourceManager,
ResourceManager) when you build a View, Editor, Composite, etc and try
to add an external resource such as an icon to a widget. It's these
classes that will be of interest to you.

Mircea



On 4/10/2010 10:16, Thomas wrote:
> hi, i defined my own icons and i want to use them in my
> rcp-application in a tree view.
>
> (ProjectStructure)
>
> -xxxProject
> --src
> --icons
> ---icons
> ----myicon.png (this icon)
>
> when i try to load them in:
>
> File f = new File("icons/icons/myicon.png");
> if(!f.exists()){
> System.out.println("doNotExist");
> }
> else{
> System.out.println("doExist");
> }
>
> File f do always not exist. Whats the Relative Path of my icon?
>
> thanks
Re: How to load icons? [message #630806 is a reply to message #630671] Tue, 05 October 2010 06:32 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 04.10.2010 16:16, Thomas wrote:
> hi, i defined my own icons and i want to use them in my rcp-application
> in a tree view.
>
> (ProjectStructure)
>
> -xxxProject
> --src
> --icons
> ---icons
> ----myicon.png (this icon)
>
> when i try to load them in:
>
> File f = new File("icons/icons/myicon.png");
> if(!f.exists()){
> System.out.println("doNotExist");
> }
> else{
> System.out.println("doExist");
> }
>
> File f do always not exist. Whats the Relative Path of my icon?

You should not expect a "normal" file name, because bundles are
designed to be located at possibly remote locations. If you need
to load an image, you should use the provided API. A simple
strategy is:

URL url = FileLocator.find(bundle, path, null);
if (url != null) {
return ImageDescriptor.createFromURL(url);
} else {
return ImageDescriptor.getMissingImageDescriptor();
}

which returns an ImageDescriptor for the given Bundle Instance bundle
and the relative path 'path', e.g.

path = Path.ROOT.append("icons").append("icons").append("myicon.png ")

for your example above.

For properly managing your image-resources I recommend that you store
them in the ImageRegistry of your AbstractUIPlugin derivative. The
overideable method initializeImageRegistry is a good place to do that.

HTH & Greetings from Bremen,

Daniel Krügler
Re: How to load icons? [message #630939 is a reply to message #630671] Tue, 05 October 2010 14:49 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

As Daniel mentioned, if you are already consuming AbstractUIPlugin you
can use
org.eclipse.ui.plugin.AbstractUIPlugin.imageDescriptorFromPl ugin(String,
String) which already does most of the work for you.

On top of that, a useful pattern is like the one used in
ActionContributionItem. When creating the Image from the
ImageDescriptor, use LocalResourceManager and back it by
JFaceResources.getResources();


PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:Define for extensions if they should be used depending on their environment (stand-alone / Eclipse)
Next Topic:org.eclipse.ant.core.antRunner application differences between 3.4.1 and 3.6.1
Goto Forum:
  


Current Time: Wed Apr 24 14:41:11 GMT 2024

Powered by FUDForum. Page generated in 0.03561 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top