JSwing - JTable

ivanthepro
ivanthepro used Ask the Experts™
on
I went to Java Web Start 1.2, to take a look at the swing set demo. There you can see an example on JTables. It displays a custom table which excepts an ImageIcon.
I looked at its source code and it says this:

ImageIcon strawberry = createImageIcon(...);
...
...
...
Objects[][] data = {{.........,strawberry},{...}}

from the api there is no such method as createImageIcon(...). So I presume its extended from the demomodule, can anyone tell me how this method is written? I tried to use all methods like setting the ImageObserver etc but none seems to match to the example in this swingset

Anyone can help pls?

TIA

Ivan
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
hm i guess that line can be replaced by :

ImageIcon strawberry = new ImageIcon("filename");

:)
-=[sKySh@DoW]=-
Java Developer
Top Expert 2010
Commented:
From the DemoModule source:

    public ImageIcon createImageIcon(String filename, String description) {
     if(getSwingSet2() != null) {
         return getSwingSet2().createImageIcon(filename, description);
     } else {
         String path = "/resources/images/" + filename;
         return new ImageIcon(getClass().getResource(path), description);
     }
     }
is there anything wrong with my codes? i've never used swingsets before .. i'm a newbie .. hehehe ..

objects:
from your codes .. it seems like it's a method that returns an imageicon ..

ImageIcon strawberry = new ImageIcon("filename");
----------------------------------------------------------
String path = "/resources/images/" + filename;
        return new ImageIcon(getClass().getResource(path), description);


don't they end up doing the same thing?

:)
-=[sKySh@DoW]=-
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Mick BarryJava Developer
Top Expert 2010

Commented:
Similiar though a bit different how they locate file.
Your code loads the image from a file directly.
The SwingSet code loads it from a URL, plus the named image needs to be accessible by the classloader.

(Plus you're doesn't set the description).
objects:
thks for that ..
by the way .. i was too lazy to type the description part .. hheeeehhee
thks

:)
-=[sKySh@DoW]=-

Author

Commented:
i tried all of your methods, but it seems like the JTable only displays the url instead of the pic?

Author

Commented:
sorry, my mistake...

okok you are correct
Mick BarryJava Developer
Top Expert 2010

Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial