• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to invoke action in parent

 
Jiri Nejedly
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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


 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • 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: 83
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's stopping you from putting it in a for loop?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!