ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
import java.awt.*;
import javax.swing.*;
public class MainClass extends JFrame {
private ImageIcon image = null;
public MainClass() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(320, 240);
// load the image to use on the titlebar
image = new ImageIcon("google.gif");
setIconImage(image.getImage());
setVisible(true);
}
public static void main(String[] args) {
MainClass test = new MainClass();
}
}
I've used the google gif for testing and it worked. Make sure the image is on the same directory as your class
Last edited by Mega Man X; 02-21-2006 at 06:35 AM.
That does not work. It leaves the space provided for the icon blank. Any reason why... where does that function take the image from?
That's the thing. That image does not exist, so the toolkit leaves it blank. If you specify your image to the path, it should work, as in the example above. I usually use a similar code to change the cursor to a blank cursor when creating games with Java
I tried what you said but that did not work and the icon is in the class's folder. Maybe there is another reason. In fact I took an icon file(ccs.ico) and renamed it as ccs.gif. Any picture viewer sees it as a correct image but maybe that is causing a problem? Is there any other way?
I'm not familiar with .ico images, but one thing is for certain: Renaming a file won't change its attributes. I mean, it will still be a ico type file. I think Gimp could convert it to some format that Java can use, such as bmp, jpg, png, gif and etc.
You're welcome mate . I think the loss of color is normal. The ico you're trying to convert has (I guess) less colors then the new image type. Maybe creating a new icon from scratch should work perfectly
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.