This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Notification Question

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • 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.
 
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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
Mac OS X IntelliJ IDE Chrome
  • 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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic