LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-20-2006, 05:49 AM   #1
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Rep: Reputation: 30
Question Setting an icon to a JFrame's Title bar


Hi guys ,

I was wondering if anyone knew how to add an icon to the title bar of all the JFrames of an Application and also of All the JInternal Frames.
Thanks.
 
Old 02-20-2006, 06:06 AM   #2
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Doesn't JFrame have a setIconImage method? Something like this:

Image img = Toolkit.getDefaultToolkit().getImage("image.jpg");
setIconImage(img);
 
Old 02-20-2006, 06:09 AM   #3
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Original Poster
Rep: Reputation: 30
That does not work. It leaves the space provided for the icon blank. Any reason why... where does that function take the image from?
 
Old 02-20-2006, 06:23 AM   #4
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Try something like this:

Code:
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.
 
Old 02-20-2006, 06:28 AM   #5
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Quote:
Originally Posted by MRMadhav
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
 
Old 02-20-2006, 07:43 AM   #6
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Original Poster
Rep: Reputation: 30
Sorry for the late reply!

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?
 
Old 02-20-2006, 07:57 AM   #7
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Original Poster
Rep: Reputation: 30
Ok, I cross checked the procedure with other gif images and it worked! whats wrong with my image?
 
Old 02-20-2006, 08:41 AM   #8
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
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.
 
Old 02-20-2006, 09:32 AM   #9
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Original Poster
Rep: Reputation: 30
Ok thanks it worked, but there is a small color problem when i converted it! Thanks again for your help!
 
Old 02-20-2006, 10:14 AM   #10
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
window without a title bar using xlib CarzyIvan Programming 1 02-11-2006 04:21 PM
Konsole title bar LocoMojo Linux - Software 2 01-22-2006 10:02 AM
Title bar font qtrob Linux - Software 3 03-31-2005 06:27 PM
Remove title bar simao20 Linux - Newbie 3 04-15-2004 11:30 PM
Firefox Title Bar Icon servo_fan Linux - Software 4 03-23-2004 10:41 AM


All times are GMT -5. The time now is 12:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration