• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

App icon

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.
  • 2
1 Solution
Jim CakalicSenior Developer/ArchitectCommented:
Use Frame.setIconImage(Image):

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

Best regards,
Jim Cakalic
Jim CakalicSenior Developer/ArchitectCommented:
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( ....... );
    JDialog dialog = new JDialog(dummyFrame, ...);

Best regards,
Jim Cakalic

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now