创建后如何在JTextField中设置新文本? [英] how to set new text in JTextField after creation?

查看:123
本文介绍了创建后如何在JTextField中设置新文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jTextField,我在创建框架时将其值设置为一定的和.
这是启动代码:

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! :)

推荐答案

在再次设置框架可见之前,应使用新的值/状态更新字段.
像这样:

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.

这篇关于创建后如何在JTextField中设置新文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆