Skip to main content

What is the right way to change the active JInternalFrame for and MDI app?

2 replies [Last post]
ianleslie
Offline
Joined: 2006-02-17
Points: 0

I asked this question on the old java.sun.com site but recieved no answers. I am hoping that on a desktop oriented site there will be more developers who have worked with MDI.

I am working on my own implementation of the window menu. The action that is triggered when a customer chooses a window to activate is not behaving as I expected. The code I wrote (below) switches frames correctly but the caption bar never gets updated and if you restore a frame from an icon the frame is not correctly activated (there is even a restore button which if you push fixes things up and the frame then behaves normally)

	if (frameToActivate.isIcon ())  {<br />
		//  Restore from icon<br />
		desktopPane().getDesktopManager().deiconifyFrame (frameToActivate);<br />
	}<br />
	desktopPane().getDesktopManager().activateFrame (frameToActivate);<br />
	desktopPane().setSelectedFrame (frameToActivate);

I did a search of the web and found a tip on JavaWorld (http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-mdi.html) which led me to try doing this from a different angle - the JInternalFrame's point of view. This code works
	try {<br />
		if (frameToActivate.isIcon ())  {<br />
			//  Restore from icon<br />
			frameToActivate.setIcon (false);<br />
		}<br />
		frameToActivate.moveToFront();<br />
		frameToActivate.setSelected (true);<br />
	} catch (PropertyVetoException error) {<br />
		error.printStackTrace();<br />
	}
My question is why does the desktop based approach not work? If methods exist that appear to let you restore and switch between frames why are the ineffective? Am I missing something obvious that I should be doing?

If using the JInternalFrame methods is the right way to go then I will uset them. It just seems like if the DesktopManager has methods that advertise support for managing the active frame then they should work. Before I ignore them I want to check with you to see if there is a right way to use them.

IL

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous

Hi,

> I asked this question on the old java.sun.com site
> but recieved no answers. I am hoping that on a
> desktop oriented site there will be more developers
> who have worked with MDI.

I am watching both the sun forum and this one and I don't know how I meesed this question there :-)

> I am working on my own implementation of the window
> menu. The action that is triggered when a customer
> chooses a window to activate is not behaving as I
> expected. The code I wrote (below) switches frames
> correctly but the caption bar never gets updated and
> if you restore a frame from an icon the frame is not
> correctly activated (there is even a restore button
> which if you push fixes things up and the frame then
> behaves normally)[code] if (frameToActivate.isIcon
> ()) {
> // Restore from icon
> desktopPane().getDesktopManager().deiconifyFrame
> e (frameToActivate);
> }
> desktopPane().getDesktopManager().activateFrame
> (frameToActivate);
> desktopPane().setSelectedFrame
> (frameToActivate);[/code]

Well, I am not 100% sure on my answer but this is what I could quickly think of.
The caption bar (you mean title bar right? ) is handled by a separate UI. So, you can't expect DesktopManager to go and update the UI's. Normally UI will call these operations on the DesktopManager. You should not call methods on DesktopManager as far as you want to have some specific requirement. The reason why I am saying this is there are other functions to be performed (like painting the caption bar, etc.,) which is done by the UI's and this is possible only when certain events are fired because these UI's listen for the events and does the action based on the event fired. So, what you are missing here is some firing of events.. like SELCTED, ICONIFIED, etc., (see the doc of JInternalFrame). I think if you fire the appropriate events here (please check out what are the events to be fired and ensure you didn't miss anything ), you will be getting the correct result. But again I strongly recommend you not to call any methods on the DesktopManager.

> I did a search of the web and found a tip on
> JavaWorld
> (http://www.javaworld.com/javaworld/jw-05-2001/jw-0525
> mdi.html) which led me to try doing this from a

Good link. Thanks for posting :-).

> different angle - the JInternalFrame's point of view.
> This code works[code] try {
> if (frameToActivate.isIcon ()) {
> // Restore from icon
> frameToActivate.setIcon (false);
> }
> frameToActivate.moveToFront();
> frameToActivate.setSelected (true);
> } catch (PropertyVetoException error) {
> error.printStackTrace();
> }[/code]

I think setIcon(false) alone should work...that will by default select tha frame..but not sure..try that.

> My question is why does the desktop based
> approach not work? If methods exist that appear to
> let you restore and switch between frames why are
> the ineffective? Am I missing something obvious that
> I should be doing?

As I said, its not just the Desktop doing the functions.. There are lot other guys participating in activating, iconifying, deiconifying, etc., like InternalFrameUI, DesktopIconUI, DesktopUI, InternalFrameTitlePaneUI, etc.., and they all listen for some proper events and act based on those events (what else cud you think of other than firing events :-) ). So go by the second approach.

> If using the JInternalFrame methods is the right way
> to go then I will uset them. It just seems like if
> the DesktopManager has methods that advertise support
> for managing the active frame then they should work.

The methods in the DesktopManager can be used if you want to perform some unique operations like Activating two frames at a time, etc., You can also use for these kind of normal operations. But in both the cases you should correctly and fully implement the basic necessary things like firing events , etc.., That is quite difficult right? So, why cant you go by the direct approach which does everything for you :-)

> Before I ignore them I want to check with you to see
> if there is a right way to use them.

I think by this time, you would have ignored :-)

Thanks,
Jana

ianleslie
Offline
Joined: 2006-02-17
Points: 0

Hey, thanks for the info (there are a lot of posts on the java.sun.com site's forumi so it is pretty easy to miss stuff). I just finished writing what I learned on my own to the other form . You have cleared up the why nicely (I did figure out that the desktop manager methods are responding to changes rather than initiating them). I have to say that those are very poor method names for methods that respond to changes rather than initiating them:-)

Your response contained exactly the information I was looking for - thanks for posting it even though I had figured the jist of it out on my own just yesterday (up until yesterday I was ignoring the code that did not work and using the code that did). On the other forum I posted the code I am now using. If you like post on the other forum and I'll give you the Dukes - since I cannot award them to my self.

thanks again,

IL

PS. You are correct the setIcon (false) is enough for iconified frames - so I'll tweak my code.