File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Notification Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Notification Question" Watch "Notification Question" New topic

Notification Question

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Ok, I have a JToolBar with JButtons on a JFrame with a JDesktopPane. We'll pretend that is all one class.
Now, in another class I have a JInternalFrame which I add to the JDestopPane via one of the Buttons on the JToolbar.
After I open this InternalFrame I need to disable the Button. That part is easy. But when I close the JInternalFrame, how do I notify the Button to enable itself?
Right now my JButton is static and I dot reference the JButton object from my JInternalFrame. Is this the only way? Or is there a better way? I would prefer a non-static approach.

GenRocket - Experts at Building Test Data
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gregg,
You should be able to do it with a java.beans.PropertyChangeListener. You can send a pseudo-property named "buttonState" or whatever and have either the button or its Frame listen for changes in that property. I posted a rather lengthy example here:

You certainly don't have to go to that much trouble for one component though. I used this to keep several components in a consistent state and it worked very well and is incredibly easy to use once you get the Mediator running.
Hope this helps,
Michael Morris

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

But the button knows about the JInternalFrame because it's launching it, right?

Try something like this in the actionPerformed method of the button...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

That's interesting Nate. I had never thought of trying that. I will see how it works for me.
Michael. Thanks for your reply as well.
I agree. Here's the link:
subject: Notification Question
It's not a secret anymore!