Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2008

Tip: Looking for answers? Try searching our database.

Customise Application Icon

Thread view: 
Leigh - 10 Jan 2008 01:42 GMT
I can't find where the main form's application icon is referenced in my
project code, or available as a Property to change.  I would like to use
another icon(instead of the default coffee cup).  How can I reference my
own icon?
Andrew Thompson - 10 Jan 2008 05:11 GMT
>I can't find where the main form's ..

Form?  There is no 'form' in the J2SE.  It sounds like
you are 'talking the language of your IDE'.  I suggest
learning Java instead.

>..application icon is referenced in my
>project code, or available as a Property to change.  

It a 'form' translates to a JFrame, then it would not.
You get the 'coffee cup' if no application icon has
been set on the JFrame.  If you set the icon to 'null'
the JFrame will have no icon, or else you can set it
to any other image understood by Java.

>..I would like to use
>another icon(instead of the default coffee cup).  How can I reference my
>own icon?

<http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setIconImage(java.
awt.Image

)>

Signature

Andrew Thompson
http://www.physci.org/

Leigh - 10 Jan 2008 12:31 GMT
>> I can't find where the main form's ..
>
> Form?  There is no 'form' in the J2SE.  It sounds like
> you are 'talking the language of your IDE'.  I suggest
> learning Java instead.

Thanks for your kind words Andrew.  I used the word "form" in a  generic
sense (perhaps influenced from prev experience with C++).  I made the
basic NetBeans example Java Desktop application.  this doesn't create a
JFrame, rather a frameView, whatever that is, as it's top level
container I think.

I am learning java, and I've always found not being afraid of asking
questions is a helpful aid.  Bye the way, one needs to learn an ide as
well as java at the beginning.  I don't want to learn java only using
the console.  Life is too short for that.

>> ..I would like to use
>> another icon(instead of the default coffee cup).  How can I reference my
>> own icon?
>
> <http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setIconImage(java.
awt.Image

> )>

Gosh, it's not easy is it?  I am finding it tricky so far to create an
image object to put in the user code field in the IconImage property of
a test JFrame I added to my project to try your suggestion. I can't yet
find an Image class in the java.awt.Image package.  Hmmm, I'll struggle on.
Andrew Thompson - 11 Jan 2008 02:13 GMT
>>> I can't find where the main form's ..
>>
[quoted text clipped - 3 lines]
>
>Thanks for your kind words Andrew.  

(dismissive) Puh!  The only kindness I will generally
offer to posters is to reply.  Thereafter I usually aim for
'techically specific' - which although it is not 'unkind' it
often ends up being 'direct and blunt'.

>..I used the word "form" in a  generic
>sense (perhaps influenced from prev experience with C++).  

I don't understand that comment.  Surely the C++ compilers
are just as finicky as the Java compilers, but if you're refering
to the C++ usenet groups - I can only assume that it takes
longer to get to a positive result that way.

>..I made the
>basic NetBeans example Java Desktop application.  this doesn't create a
>JFrame, rather a frameView, whatever that is, as it's top level
>container I think.

You think?  This is the sort of comment that inspires
me to say 'understand it from the command line first'.

The fact is that NetBeans (last time I checked) had
relatively ways to see the 'inheritance tree' of any Java
object, so it should be relatively easy to tell others what
this 'frameView' actually is.  Further, the lower case initial
'f' suggests this is a reference variable name, rather than
a class.  E.G. ..
 // FrameView is a class, frameView is a reference to an instance of
FrameView.
 FrameView frameView = new FrameView("Frame Title");

Please try to wuote class names, rather than the name of
the variable (and if the class name is truly 'frameView' - it
seems whoever wrote it was a nonser and the code should
probably be avoided completely).

>I am learning java, and I've always found not being afraid of asking
>questions is a helpful aid.  Bye the way, one needs to learn an ide as
>well as java at the beginning.  

That is something I strongly disagree with.
Ant and a simple editor is all that is needed to 'learn Java',
and gives a good foundation for understanding any IDE.

>..I don't want to learn java only using
>the console.  Life is too short for that.

I warrant you will waste a lot more time trying to 'figure
the IDE' that way, and ultimately (over a long period)
that will lead to lower productivity.

So to put it back to you..
" Life is too short for 'learning' IDEs."

>>> ..I would like to use
>>> another icon(instead of the default coffee cup).  How can I reference my
[quoted text clipped - 4 lines]
>
>Gosh, it's not easy is it?  

There are some 'roundabout'* factors in creating an icon
image for an app.

>..I am finding it tricky so far to create an
>image object to put in the user code field in the IconImage property of
>a test JFrame I added to my project to try your suggestion. I can't yet
>find an Image class in the java.awt.Image package.  Hmmm, I'll struggle on.

Hmm.. well I realise you were not asking specifically for further
help, but I will include a simplistic* example anyway.

<sscce>
import java.awt.*;
import javax.swing.*;
import java.net.URL;

class FrameWithIcon {
 public static void main(String[] args) throws Exception {
   final URL url = new URL(
     "http://forum.java.sun.com/images/answer-correct-24x24.gif");
   Runnable r = new Runnable() {
     public void run() {
       Image icon = Toolkit.
         getDefaultToolkit().
         createImage(url);
       JFrame frame = new JFrame("Icon");
       frame.setDefaultCloseOperation(
         JFrame.EXIT_ON_CLOSE);
       frame.setIconImage(icon);
       frame.setSize(400,400);
       frame.setLocationRelativeTo(null);
       frame.setVisible(true);
     }
   };
   EventQueue.invokeLater(r);
 }
}
</sscce>

* The example avoids some 'where is my sh*t?' hassles
by grabbing the image direct from the net, rather than
from the jar archive that contains the application.  The
second situation might encounter some problems finding
the URL to the image, especially if called from the main()
method.

Signature

Andrew Thompson
http://www.physci.org/

colinbankier@hotmail.com - 17 Jan 2008 06:37 GMT
Hi,

I think I can give you a little more help. Netbeans uses the Swing
Application Framework as the basis of desktop example projects. The
FrameView object is part of this framework.
You can use Andrew's example to see how to create an Image (stored in
the variable 'icon'), then you can simply call:
getFrame().setIconImage(icon);
from inside the contructor of the FrameView.

The docs for the Swing Application Framework can be found at
https://appframework.dev.java.net/nonav/javadoc/AppFramework-1.03/index.html

Cheers,
Colin.
Leigh - 10 Jan 2008 12:33 GMT
>> I can't find where the main form's ..
>
> Form?  There is no 'form' in the J2SE.  It sounds like
> you are 'talking the language of your IDE'.  I suggest learning Java
instead.

Thanks for your kind words Andrew.  I used the word "form" in a  generic
sense (perhaps influenced from prev experience with C++).  I made the
basic NetBeans example Java Desktop application.  this doesn't create a
JFrame, rather a frameView, whatever that is, as it's top level
container I think.

I am learning java, and I've always found not being afraid of asking
questions is a helpful aid.  Bye the way, one needs to learn an ide as
well as java at the beginning.  I don't want to learn java only using
the console.  Life is too short for that.

>> ..I would like to use another icon(instead of the default coffee
cup).  How can I reference my own icon?

<http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setIconImage(java.
awt.Image

> )>

Gosh, it's not easy is it?  I am finding it tricky so far to create an
image object to put in the user code field in the IconImage property of
a test JFrame I added to my project to try your suggestion. I can't yet
find an Image class in the java.awt.Image package.  Hmmm, I'll struggle on.
cartimon@gmail.com - 07 Feb 2008 23:52 GMT
> I can't find where the main form's application icon is referenced in my
> project code, or available as a Property to change.  I would like to use
> another icon(instead of the default coffee cup).  How can I reference my
> own icon?

...
...
//
import java.awt.Toolkit;
import java.awt.Image;

/**
* The application's main frame.
*/
public class Adm0View extends FrameView {

   public Adm0View(SingleFrameApplication app) {
       super(app);
           // change default icon
           Toolkit kit = Toolkit.getDefaultToolkit();
           Image frameIcon = kit.getImage("FD2.jpg");
           getFrame().setIconImage(frameIcon);
           // PATH ..\Adm0\"FD2.jpg";

       initComponents();

...
...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.