Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

App icon

Posted on 2000-04-27
2
Medium Priority
?
245 Views
Last Modified: 2012-06-27
Hi,
How do I set a frame's icon, using a .gif file? for both JFrame and JDialog.

By setting an icon I mean like an app icon.
0
Comment
Question by:s_lavie
  • 2
2 Comments
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2756332
Use Frame.setIconImage(Image):

    Frame frame = new Frame("Application");
    ImageIcon icon = new ImageIcon("my_frame_icon.gif");
    frame.setIconImage(icon.getImage());

Best regards,
Jim Cakalic
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 200 total points
ID: 2756360
Sorry, that wasn't a complete answer. This works for JFrame since it extends Frame.

JDialog is another story. JDialog will use whatever icon image its parent Frame uses. You set the parent Frame of a JDialog by using one of the four JDialog constructors that has 'Frame owner' as its first argument.

If you want your JDialog to have a different icon image or you don't want to (or can't) set an existing Frame as the dialog owner, you can create a dummy JFrame, set its image, and make this the owner of the JDialog.

    JFrame dummyFrame = new JFrame();
    ImageIcon icon = new ImageIcon( ....... );
    dummyFrame.setIconImage(icon.getImage());
    JDialog dialog = new JDialog(dummyFrame, ...);

Best regards,
Jim Cakalic

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question