Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Notification Question

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the button knows about the JInternalFrame because it's launching it, right?

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

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic