Adding JTextField that has to listen to updates

I have to modify an existing application and add a field that should constantly show a value that is calculated and not shown in many places in the existing code.

As I am new to this I added a JTextField and set its value to the initial value. That worked.

Now in most of the places this value is calculated I do not have direct access to that JTextField. I do not want to add a global variable as I am afraid to destablize the code. Moreover, in the few places I do have access to it, I tried calling setText but the field would not refresh with the new value.

I am sure I am missing something very basic here regarding the mechanics of this. Should I fire an event ? which/how ? a reference to an example would be highly appreciated.

Thanks for any thought.

[790 byte] By [mye6809a] at [2007-11-27 10:16:35]
# 1

Hi,

I'm not sure if I understood your requirement correctly, but there's a new JSR and reference implementation under development, which might help you:

Beans Binding (JSR 295): https://beansbinding.dev.java.net/

I don't know the current state of that project, though.

-Puce

Pucea at 2007-7-28 15:46:27 > top of Java-index,Desktop,Core GUI APIs...
# 2

A global variable should not create problems.

But if you want, you can create a method in the class where you declared the JTextField that takes in input the new String to set to the JTextField. In this method you put:

myTextField.setText(myString);

And everything is done. You may try to call revalidate() or repaint() if something does not work..but anything should be successful

albertthea at 2007-7-28 15:46:28 > top of Java-index,Desktop,Core GUI APIs...