how to set new text in JTextField after creation?

Daniel Briskman picture Daniel Briskman · Jun 15, 2011 · Viewed 79.4k times · Source

I have a jTextField , and I set it's value to a certain sum when I create the frame.
Here is the initiation code:

totalTextField.setText(
            itemsPriceTextField.getText() +           
                    Float.toString(orderDetails.delivery)
);

This textfield should show a sum of items selected by the user.
The selection is done on a different frame, and both frames are visible / invisible at a time.
The user can go back and forth and add / remove items.

Now, every time i set this frame visible again, I need to reload the value set to that field
(maybe no changes were made, but if so, I need to set the new correct sum) .

I'm quite desperate with it.
Can anyone please give me a clue?
Thanks in advance! :)

Answer

Daniel Briskman picture Daniel Briskman · Jun 15, 2011

Before setting the frame visible again, one should update the fields with the new values / states.
something like:

jTextField.setText("put your text here");  
jRadioButton.setSelected(!isSelected());  
.  
/* update all you need */
.  
jFrame.setVisible(true);

The frame will come up with the new values / states.