JFrame.SetIconImage

I am having trouble with JFrame.SetIconImage. When I set this to a .jpg or .gif, the image does not display. The cup image does not dispaly either. My image resides in the same directory as my .class.Any Suggestions?Thanks
[243 byte] By [Rene-Ka] at [2007-11-26 15:50:24]
# 1
Are you sure your image is loading in the first place? Make sure it's loading correctly by displaying it in a label in your gui. If this works, try making a bitmap copy of the image.
tjacobs01a at 2007-7-8 22:10:09 > top of Java-index,Java Essentials,New To Java...
# 2

A simple example

import java.awt.*;

import javax.swing.*;

import java.net.*;

public class Fred204 extends JPanel

{

public Fred204() throws Exception

{

super(new BorderLayout());

setPreferredSize(new Dimension(100,100));

}

public static void main(String[] args) throws Exception

{

JFrame frame = new JFrame("Fred204");

URL imageURL = Fred204.class.getResource("your_gif.gif");

ImageIcon imageIcon = new ImageIcon(imageURL);

frame.setIconImage(imageIcon.getImage());

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setContentPane(new Fred204());

frame.pack();

frame.setVisible(true);

}

}

This assumes that your_gif.gif is in the same directory as the class file Fred204.class .

sabre150a at 2007-7-8 22:10:09 > top of Java-index,Java Essentials,New To Java...
# 3
Post your code
qUesT_foR_knOwLeDgea at 2007-7-8 22:10:09 > top of Java-index,Java Essentials,New To Java...
# 4

Thanks tjacobs01. This pointed me in the right direction. My image was not loading as it resided in the same directory as the .class file. As this class was created as part of a Project, the image needed to reside in the directory for the Project and not the .class. When calling the .class from Delphi through JNI, the image needs to be in the directory of the Delphi program.

But, thanks, this got me looking in the right direction.

Regards

Rene

Message was edited by:

Rene-K

Rene-Ka at 2007-7-8 22:10:09 > top of Java-index,Java Essentials,New To Java...