tags:

views:

1156

answers:

5

I know I can specify one for each form, or for the root form and then it'll cascade through to all of the children forms, but I'd like to have a way of overriding the default Java Coffee Cup for all forms even those I might forget.

Any suggestions?

A: 

Extend the JDialog class (for example name it MyDialog) and set the icon in constructor. Then all dialogs should extend your implementation (MyDialog).

andreasmk2
+4  A: 

You can make the root form (by which I assume you mean JFrame) be your own subclass of JFrame, and put standard functionality in its constructor, such as:

  this.setIconImage(STANDARD_ICON);

You can bundle other standard stuff in here too, such as memorizing the frame's window metrics as a user preference, managing splash panes, etc.

Any new frames spawned by this one would also be instances of this JFrame subclass. The only thing you have to remember is to instantiate your subclass, instead of JFrame. I don't think there's any substitute for remembering to do this, but at least now it's a matter of remembering a subclass instead of a setIconImage call (among possibly other features).

Paul Brinkley
Not ideal, but it works. There should be a way of doing this for all forms in an app. Some forms might be spawned by third party tools, etc.
Allain Lalonde
Yes, there *should* be a way, but sun hasn't provided one. Its probably a sev3 enhancement in bugparade somewhere...
John Gardner
+1  A: 

Also, if you have one "main" window, and set its icon properly, as long as you use that main window as the "parent" for any Dialog classes, they will inherit the icon. Any new Frames need to have the icon set on them, though.

as Paul/Andreas said, subclassing JFrame is going to be your best bet.

John Gardner
+1  A: 

There is another way, but its more of a "hack" then a real fix....

If you are distributing the JRE with your Application, you could replace the coffee cup icon resource in the java exe/dll/rt.jar wherever that is with your own icon. It might not be very legit, but it is a possibility...

John Gardner
Agreed. It'd work, but I'm not feeling that desperate. :)
Allain Lalonde
If it's the only way, it doesn't matter if you're desperate or not :) My company does it through InstallAnywhere's `executableIcon` property. I think it does it by replacing `JavaCup.png` in `jre/lib/resources.jar`.
Geoffrey Zheng
A: 

There may be a way of doing it using the Look and Feel overriding the UIDefaults. I'm just not sure which index would do.

Allain Lalonde