2

I'm using the card layout to create my app, 2 of my cards are shearing the same information (in one you enter data to textarea and in the other the data is printed). The data is been saved in the Frame. I have added a refresh function to the second card that get the value and print it, But I don't know how to trigger it.

Is there any event that can be bind to this function? Or any other way to get to the card functions from the frame (so I can trigger it every time I show the card)?

Thanks'

guy ergas
  • 135
  • 3
  • 10

1 Answers1

2

There are generally two ways of achieving what you are after. Either you update/refresh the output card whenever it is displayed, like you suggested. This can be done by adding a ComponentListener to the Component that you use as your output card. This way you can override the componentShown method so that it calls your custom refresh method. See the accepted answer for this question.

The second alternative is to call refresh whenever any of the data is changed - always keeping it up to date, even when it is not actually visible. Depending on how your application looks this might be done in different ways. If you have a dedicated data model then you could use the Observer / Observable pattern to notify changed from an internal model, or you could hard-code the model to call refresh whenever it is changed. If you just want to get the data directly from the input fields on the first card, then you could just add that code into their respective change listeners etc.

Community
  • 1
  • 1
Jiddo
  • 1,256
  • 1
  • 10
  • 15