• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to invoke action in parent

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I seeking how to implement this beahavior:

I have form, with JTextField(s). I added some new beahvior to text field (MyJTextField) - it turns yellow, after any edit and it can be asked if it was edited. But I don't want to ask if the field was edited myself and then do some action - for example disable navigate buttons.

I want the field to disable button itself, trigger some action in parent after editing.

Because MyJTextField is in separate class, it doesn't know anything about parent's elements.


P.S.: Long before Java i worked in environment called Centura. There all was about sending 'messages'. The child element simply sent certain message to parent (or any other object). If parent 'knew' this particular message, it served it, if not, nothing happened.

So far I cannot find any similarity with this in swing.

Here's my source code


 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't make your components listeners as well. You should use separate (anonymous) classes to handle events for you. Here's how you can do it for your problem:
 
Jiri Nejedly
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, but what if I have 20 identical text fields ? Do I have to write 20 times the same code?





 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's stopping you from putting it in a for loop?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic