Answers

Question and Answer:

  Home  Java GUI Framework

⟩ How to replace the icon in the title bar (window decoration) of a [J]Dialog?

There is only a partial solution to this problem, and it is not recommended.

A dialog gets its icon from its parent frame. You can create a dummy frame, set the icon of that dummy frame, and use it in the constructor of the dialog as the dialog's owner:

JFrame dummy = new JFrame();

Image icon = ...

dummyFrame.setIconImage(icon);

JDialog dialog = new JDialog(dummy);

However, this is dangerous. Certain GUI behavior depends on a correct [J]Frame (parent window) <-> [J]Dialog (child window) relation. Introducing a dummy parent breaks this relation. Things which can go wrong include (de)iconising of all windows of an application, and ensuring a modal dialog is always placed on-top of the main window.

 161 views

More Questions for you: