DualList.getResourceString read image path from jar file

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

DualList.getResourceString read image path from jar file

Postby onlyhuman » Thu Apr 17, 2014 10:24 pm

Hello,

I am wondering when will it be possible in DualList.getResourceString() can read/extract an image path inside a jar which is on the classpath.

I've tried to extract to a temporary file, but since it is not on the classpath it does not work. Is there any workaround to achieve this?
I am using framework version 2.4.5.
Thanks in advance!

Best regards,
Robert
onlyhuman
 
Posts: 6
Joined: Mon Apr 04, 2011 7:51 am

Re: DualList.getResourceString read image path from jar file

Postby JIDE Support » Thu Apr 17, 2014 10:36 pm

Sure. You just need to start from root when you define the icon path. Something like "/com/company/icons/someIcon.png".
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: DualList.getResourceString read image path from jar file

Postby onlyhuman » Fri Apr 18, 2014 1:36 am

Thank you for your quick response! But I was unable to load my custom icon.

The structure of my jar:
/classes/com/mycompany/*
/resources/*

Path ClassLoader JIDE
/com/mycompany/path/to/icons/someIcon.png X X
com/mycompany/path/to/icons/someIcon.png OK X
/classes/com/mycompany/path/to/icons/someIcon.png OK X
classes/com/mycompany/path/to/icons/someIcon.png X X

OK means working
X means not working
The class loader command I used:
com.mycompany.CustomDualList.class.getClassLoader().getResource("/classes/com/mycompany/path/to/icons/someIcon.png"));
I have also tried the resources directory without success.

How the framework handling this? Or what I am doing wrong?
onlyhuman
 
Posts: 6
Joined: Mon Apr 04, 2011 7:51 am

Re: DualList.getResourceString read image path from jar file

Postby JIDE Support » Fri Apr 18, 2014 7:56 am

Do you actually have "classes" in your package name? I am not saying it is not okay but very unusual. Package name usually starts with /com/company/ or /company/ (without com). And I wonder that has caused the problem. If you don't use "classes", then "/com/mycompany/path/to/icons/someIcon.png" is the right one to refer to the image file.

Internally we use class.getResourceAsString to get the image file. The "class" would always be DualList.class. In other word, if the class loader of DualList.class can find the resource file, it should load the file correctly.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: DualList.getResourceString read image path from jar file

Postby onlyhuman » Wed Apr 23, 2014 12:10 am

Actually I don't have "classes" in the package name, but my jar file has two subfolders: classes and resources.
Since I am using Java Plugin Framework all of my jar files has this structure, but on the classpath this path is resolved. Due to this I can only use absolute path for an image file inside a jar:
jar:file:/C:/my/local/path/main.jar!/resources/images/someIcon.png
I am extending your DualList class to customize it e.g. with my icons too.
onlyhuman
 
Posts: 6
Joined: Mon Apr 04, 2011 7:51 am

Re: DualList.getResourceString read image path from jar file

Postby onlyhuman » Wed Apr 23, 2014 1:17 am

I made a test today:
I've put this line in my code:
System.out.println(String.format("Key: %s value: %s\tgetClass().getResourceAsStream: %s\tDualList.class.getResourceAsStream: %s", key, result, getClass().getResourceAsStream(result)==null?"NOT found":"FOUND", DualList.class.getResourceAsStream(result)==null?"NOT found":"FOUND"));
And I got this result:
Key: dualList.moveLeft.icon value: /com/my/companylsyh/path/to/images/someIcon.png getClass().getResourceAsStream: FOUND DualList.class.getResourceAsStream: NOT found

So the problem is: my custom class's classloader find the searched icon, but DualList.class's classloader does not. Would it be possible to change your code from DualList.class.getResourceAsStream to getClass().getResourceAsStream? Or is there any workaround?
Thanks in advance!
onlyhuman
 
Posts: 6
Joined: Mon Apr 04, 2011 7:51 am

Re: DualList.getResourceString read image path from jar file

Postby JIDE Support » Wed Apr 23, 2014 6:51 am

Having subfolder in the jar will definite causing problem. We use IconFactory.getImageIcon everywhere in our code where the class is passed in as parameter to getImageIcon. In DualList.java, we passed in DualList.class. What I can do is to add a protected method like this one below. If that'll work, it will be available in the next release.

Code: Select all
    /**
     * Subclass can override this method to provide the imageIcon.
     * @param url url to the icon
     * @return ImageIcon
     */
    protected ImageIcon getImageIcon(String url) {
        return IconsFactory.getImageIcon(DualList.class, url);
    }
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 17 guests