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?
Specifically, I'm looking for some set of behavior equal to or greater
than the following:
When an internal frame is iconified AND the look and feel has
located that iconified frame at the bottom of the desktop AND the
desktop is resized, THEN the iconified frame should reoccupy the
appropriate position in the newly-sized desktop.
Right now what happens is that the iconified frame simply stays where it
is. This is in keeping with a container that really doesn't have a
layout manager, but it's not what a user would expect.
Thanks in advance for any pointers; I have done my homework via Google,
this newsgroup, etc. but haven't found anything. There are plenty of
examples of putting a JDesktopPane into a JScrollPane, but for various
reasons I'd really REALLY like to avoid this if possible.
Thanks,
Laird
Laird Nelson - 24 May 2005 21:16 GMT
> 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