🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19431

Re: How to set icon image on secondary window?

#19431
From: Paul Murray
Date: Sat, 07 Feb 1998 00:00
89 lines
4505 bytes

LiLiu wrote in message <01bd2dda$1cd9d400$5901a8c0@lilnt>...
>Hi,
>I'd like to change the icons in secondary window such as dialogbox,
>messagebox
>from the Cup (a cup of hot coffee?:) to anything I want (the .gif file).
>Is it possible to do this?
>My application is a standalone app.  I can do this for the frame window so
>that when I run my app, my icon appears on top-left corner.  I'm wondering
>how to do it with secondary window.
>Thanks.  Please send a copy to my e-mail address if you choose to answer in
>the news group.
>
>Li
>liliu@smarttech.com

Hmm. Ok, I'll have a bash.
I created a sample app with a button that opens a MessageDialog. You want to
change the cup of coffee in the top lefthand corner, right? This is part of
the windows way of doing things, so it's possible that Borland have coded it
into their window peer.

Lets look at the docs.

A MessageDialog is a ButtonDialog is a Dialog is a Window. I reckon Window
would be where that attribute was set (if it is an attribute).

Nothing obvious. There is no setIcon() method. 2 possibilities.
1 - the icon comes from the ToolKit (whatever that is)
2 - the icon is done in a protected method

Lets look at Toolkit. Hmm. There is a createWindow method which is used to
create the window. At a guess, Window probably sets itself up then calls
Toolkit.getDefaultToolkit().createWindow(this) or something similar. So it
comes back to option 2.

Use the source browser to examine how Window does it's thing.

Nothing obvious there either. The icon is probably in peer, which is system
specific. Damn. There is no variable named peer in the in Window, so it's
probably in a superclass. Yep, class Component has a transient variable peer
type ComponentPeer. This is an interface, So I can get no details on it.

So it comes down to the peer type returned by the createWindow method of the
default toolkit. Let's have a look, shall we? Toolkit is an abstract class.
It has a static method getToolkit which gets the system property
"awt.toolkit", default "sun.awt.motif.MToolkit". It expects this property to
be a classname. the method actually returns "sun.awt.windows.WToolkit" when
I run it under win95.

Let's have a look at this class with the source browser:
No source, just a decompiled definition.
So we seem to be stuck.

If we were not stuck, the steps would be:
create a Class MyToolkit extends "sun.awt.windows.WToolkit".
Override createWindow() in the toolkit. The new create window should somehow
do your icon replacement.

You now have two choices.

1 - You can use your new toolkit for all windows your app creates.
  if(System.getProperty("awt.toolkit").isequal("sun.awt.windows.WToolkit") )
   System.setProperties(xxx)
where xxx is the same as the current list of system properties but with the
"awt.toolkit" property changed to "MyPackage.MyToolkit"

2 - Subclass MyMessageBox, override getToolkit() to return a MyToolKit
instead of Toolkit.GetDefaultToolKit().
Neater, but won't affect your system boxes.

If you like, you could define an interface "WindowIconOverride" with a
function getIcon(). When MyToolkit.createWindow() is called, it could check
the Window it has been passed to see it if implements  WindowIconOverride.
If not, it uses just a default icon. You could then define a class
  MyMesssageBox extends MessageBox implements WindowIconOverride { }
and use it.

Note however, the root problem causing this complexity - icons in the
top-left corner of a window are a system-specific thing. Win 3.1 doesn't
have them. I don't know that sun has them. The root problem of the root
problem is that the java engine for Win95 doesn't support the different
icons. It would be nice if it did. Perhaps what is needed is a system for
enquiring  what customisations are possible, and being able to set them.The
system customisation state should probably be stored in Toolkit - it seems
to be the right place for it.

Hope this helps, in a way.
Technical Details
Message-ID: <6bgv2j$abg9@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <01bd2dda$1cd9d400$5901a8c0@lilnt>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,62710c266b6d6172
X-Google-Attributes: gidf74b3,public
From: "Paul Murray" <pmurray@bigpond.com>
Subject: Re: How to set icon image on secondary window?
Date: 1998/02/07
Message-ID: <6bgv2j$abg9@forums.borland.com>
X-Deja-AN: 322850601
References: <01bd2dda$1cd9d400$5901a8c0@lilnt>
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Organization: N/A
Newsgroups: borland.public.jbuilder.java.language