Re: DesktopManager implementation question



Laird Nelson wrote:
Before I go reinventing the wheel, does anyone know of a pointer to a DesktopManager implementation that handles resizing properly when its internal frames are minimized?

Not finding any such pointer, I discovered a clean hack to do what I want.

For those who are interested:

* Add a ComponentListener to the JDesktopPane that detects when it has been resized.
* Get all of its internal frames via its getAllFrames() method.
* For each of those frames THAT IS AN ICON, tell a grievous lie by putting the following client property into it:


  "wasIconOnce", "false"

This is a lie. It clearly WAS an icon once--actually it IS, right at this very moment when we're looking at it. But note that it is the evaluation of this property that causes the DefaultDesktopManager to decide whether it needs to recompute the location/bounds for the DesktopIcon. So we're effectively tricking the DesktopManager into recomputing the bounds on a resize. Note that the very first thing that the DefaultDesktopManager does at line 143 is reset the "wasIconOnce" property to TRUE, so when we're all done we haven't touched the state of things at all.
* Call desktopPane.getDesktopManager().iconifyFrame(frameInQuestion);


Works like a charm. Those who want a marginally less hackish approach will override the DesktopManager's wasIcon(JInternalFrame) method instead.

Best,
Laird
.