How to set .ico - files as icons in an Applet?

Hi, I try to use Jimi to get an Applet to load an .ico file. This should be done the same way as the java.awt.Toolkit.getImage(getCodeBase(), "iconname.gif"), with the exception that the Jimi-packet is used. Jimi is working just fine if I use it the same way as an Application but when I try to load the .ico-file with the Applet it fails. In the Applet, I have tried to load a .gif-file with the java.awt.Toolkit.getImage(..) and that works fine, so the filepath is ok. Anybody that have had this problem and solved it? Codesnippet: // load the Jimi-pack. import com.sun.jimi.core.*; // // // in the applet codeImage image; // Not sertain how to locate the ico-file. When // running as App, I just take the whole searchpath *C:\myPics\Treasury.ico* which works. //String uString = getCodeBase()+"Treasury.ico"; URL u = new URL(uString); image = Jimi.getImage(u); this.setIconImage(image);

"FiberSpar" Welcome to the JavaRanch. We have a few rules about naming that you can find here.Applets run in a security "sandbox". Whenever you have something that runs standalone and/or in the AppletViewer but not in an applet, it's usually the sandbox. The brute force way to get around that is to security-sign the applet. Signing is a pain and often it doesn't help, since running afoul of the sandbox is often an indication that you are trying to apply client/server design rules to a web server environment. Meaning that you will run across other problems later. I'm not familiar with jimi, but usually you can bundle resources - whether property files, gif's or ico's into the applet jar and use the basic applet resource access functionality to get what you need.

Customer surveys are for companies who didn't pay proper attention to begin with.

Mats Johansson
Greenhorn

Joined: Mar 31, 2003
Posts: 6

posted Apr 01, 2003 00:09:00

0

Sorry about the nickname - I tried with my real name but didn't get it work when I created my account. It worked, though, to change it. Anyway, I don't think that my problem has to do with the sandbox. As I said, the .gif - file loads just fine with java.awt.Toolkit.getImage(..). The problem should rather be the format .ico that is not *yet* supported by the java.awt package. Is that so? /mats

try to use ImgFrame imageframe.SetIcon("filename.gif"); this worked for me

Mats Johansson
Greenhorn

Joined: Mar 31, 2003
Posts: 6

posted Apr 01, 2003 09:46:00

0

I didn't manage to load any .ico -files. My best workaround is to download microangelo or something alike (http://www.microangelo.us/) and simpy convert the .ico to .gif's. Now the this.setIconImage(Image image) works fine, but the JButton.setIcon(Icon icon) does not work. This is still in the Applet env. Runnning as application works fine. Anybody who has encountered this? /mats

OK. I think there's a number of things. Unless I'm mistaken, there's only one ".ico" file format to speak of and that's proprietary to Microsoft Windows. Since Java is "write-once/run anywhere" -- AND because among other potential users of your applets, I'm not running WIndows, you aren't going to find ".ico" file support anytime soon. I think an ".ico" is a modified ".bmp", which actually isn't a very efficient way to keep graphics anyway compared to jpg's and gif's. Another problem is that JButton is a Swing construct. Thanks to Netscape's failing to keep up with the times and Microsoft's sulkiness re Java, the Java "distributed" with IE and Netscape (when supplied at all) is stuck back in the Stone Ages. Swing's not available, only AWT. Someday Sun may manage to get the courts to force Microsoft to move client-side Java into the 21st Century, but in the mean time, you have to either use only AWT GUI classes (and old AWT at that) or you have to link the Java Plug-in to the applet so that if the user doesn't already have the Plug-in installed, it will download and install. Since the Plug-in's about 1.5MB and does scary software-install-type things, you really need a captive audience before you can depend on people going to that much trouble. Swing is available to Java applications like the AppletViewer - providing the JDK is available. Since AppletViewer is distributed with the JDK, it's not a problem. But your web browser isn't aware of your JDK, just the java runtime that "came with" your browser.

Mats Johansson
Greenhorn

Joined: Mar 31, 2003
Posts: 6

posted Apr 01, 2003 23:33:00

0

Thanks for the answers. I'm actually already using the <OBJECTS> tabs to enable the downloading possibility for people who hasn't the appropriate JDK (using 1.3.1_07). This works really well and I'm pleased with the solution. The problem is to get the JButtons to display the gif's.. I might call the methods with wrong args or maybe I'm just doing something weird.. snippet: *The package in the jar-file is el/ * private Icon[] icon = new Icon[12]; private JButton saveButton = new JButton(); // // load the gif as an ImageIcon (the only way for JButtons? icon[4] = new ImageIcon(getCodeBase()+"el/SAVE.gif"); //... // call to display the button saveButton.setIcon(icon[4]);

Mats Johansson
Greenhorn

Joined: Mar 31, 2003
Posts: 6

posted Apr 02, 2003 01:11:00

0

So finally problem is solved. It's obviously not possible to instanciate the ImageIcon with the call: ImageIcon i1 = new ImageIcon(getCodeBase()+"yourGif.gif"); This is how the call should look like:ImageIcon i1 = new ImageIcon(getImage(u, "yourGif.gif")); then it's just to add it to whatever swing-component you like. If anybody has problems with following, I have now set up a working env. for the following: * The issue above (of course) * A working Applet loading the appropriate JDK for the clientmashine if she/he doesn't already have it (only tested on IExplorer). This is done with Suns HTMLConverter. * The Applet uses a certificate loaded to the .jar with the javakey and javasigner facilities. If anybody has problems with those things, just answer this thread and I'll get informed by email. I'll leave it now. Thanks!