Solved

App icon

Posted on 2000-04-27
2
233 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 50 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now