| Author |
Notification Question
|
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
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. Thanks.
|
 |
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: ComponentMediater 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
Bartender
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...
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
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.
|
 |
 |
|
|
subject: Notification Question
|
|
|