3

Set an icon for aenter image description here JFrame when it is minimized to the dock like other mac application. Please help..

Abin
  • 540
  • 4
  • 15
  • possible duplicate of [JFrame minimized dock icon setting similar to mac apps](http://stackoverflow.com/questions/18184587/jframe-minimized-dock-icon-setting-similar-to-mac-apps) – chrylis -cautiouslyoptimistic- Aug 13 '13 at 06:31
  • 2
    Exactly, but that too don't have the answer. if u have the answer then replay for that.. Blaming is not the answer – Abin Aug 13 '13 at 12:01

4 Answers4

1

An e.g. of what Mikle was referring to:

Now moved to: Sizes of frame icons used in Swing.

Icon Size Usage - showing 16x16 frame icon

Icon Size Usage - Alt+Tab

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

Window class has method setIconImages which requires java.util.List<? extends Image> as an argument. You will have to pass a list of images with different sizes so that OS can choose one from that list for each specific situation - would it be minimized icon, icon for dock/toolbar, icon for window or icon for any other system-specific UI element.

I usually pass a lot of images for my own application in different sizes: 16x16, 24x24, 32x32, 48x48, 64x64, 128x128, 256x256, 512x512

The large ones are usually used by large toolbars or by folder view to display icons for files associated with your application. Also usually 16x16 icon is used as window (frame/dialog) icon. Other icons can be used in a lot of different situations which depends on what OS you have (Windows, Mac OS e.t.c).

Mikle Garin
  • 10,083
  • 37
  • 59
  • i tried with 16X16, even though while i minimize the window it shows the image as the full icon without active window(similar to windows) – Abin Aug 13 '13 at 12:12
  • *"i tried with 16X16,.."* Get back to us once you have tried with a group of images that includes the other **7** sizes suggested by @Mikle. It would be easiest to generate them in code, with distinctive colors. – Andrew Thompson Aug 13 '13 at 13:35
  • @Abin you should specify more than just one image so that system can choose appropriate one, otherwise it will either use default one or stretch the 16x16 icon to larger size (exact behavior depends on system). – Mikle Garin Aug 13 '13 at 14:45
  • By calling `setIconImages`, you actually make the experience worse when the user minimises the window. Now they will see that icon, instead of what *all native applications* do, which is to show a miniature copy of the actual window you minimised. – Hakanai May 02 '14 at 07:18
  • @Trejkaz you are wrong - that icon will be displayed in the corner of a miniature copy of the window instead of standard Java icon, it doesn't replace the miniature itself. At least in Windows and Mac OS X. – Mikle Garin May 02 '14 at 12:50
  • @MikleGarin you are wrong - it replaces the entire miniature. At least for Java 7 and 8 on Mac OS X. You can see that NetBeans also makes the same mistake as their application also minimises to an icon instead of a miniature. – Hakanai May 04 '14 at 04:00
  • @Trejkaz for me it works as before on JDK 6, 7 and 8 - having both - window preview and icon in the corner, so this is probably an issue (or unexpected behavior changes?) in some specific Mac OS X version. A wild guess - probably you shouldn't set icons larger than 64x64 (or 128x128) - Mac OS X might interpret it as a preview instead of an icon due to its size. – Mikle Garin May 07 '14 at 10:12
  • It could be something like the icons being too big. We have all sizes of the icon because certain platforms (e.g. Mac OS X itself) demand them for other purposes. – Hakanai May 08 '14 at 03:45
0

Use the jar bundler that is available with Mac os to create an App. Set the icon of the app using jar bundler and dont set any icons for your jframe.

user2067201
  • 258
  • 1
  • 13
0

You're really talking about two things.

  1. The icon of the application in the dock, in Finder, etc.

    appbundler or even simply hand-creating the bundle is the solution to that, as already mentioned.

  2. The icon of the application when minimised to the dock

    When you minimise the application it becomes a separate dock entry which does not necessarily look like the application one.

    The Window has setIconImages - if you set this method, the application will become that icon when minimised which will not look native. So you should check if you're running on OSX before calling that method and avoid calling it.

    By leaving out the call, you get the default behaviour where the minimised icon will be a miniature copy of what the window itself looks like, which is what we see other applications doing. It would be nice if the JRE would take care of that for us and just ignore the icons when running on Mac OS X.

Hakanai
  • 12,010
  • 10
  • 62
  • 132