Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

java - 将setText与TextField结合使用(Using setText with TextField [closed])

I created a JPanel Form and I want to set a value to some TextFields.

(我创建了一个JPanel表单,我想为某些TextFields设置一个值。)

I created in the design window of netbeans the textfields that I need, but in the source windown I don't know how to add text to those textFields that I created.

(我在netbeans的设计窗口中创建了我需要的文本字段,但是在源窗口中,我不知道如何向我创建的那些textField中添加文本。)

The only thing that I know is that I have to use setText method, but I'm a bit lost and I don't know how to use it.

(我唯一知道的是必须使用setText方法,但是我有点迷茫,我不知道如何使用它。)

Any help please?

(有什么帮助吗?)

  ask by Kernel translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The JTextField setText method takes a string as a parameter.

(JTextField setText方法采用字符串作为参数。)

This string is what will be shown in the textfield.

(该字符串将在文本字段中显示。)

An example could be

(一个例子可能是)

JTextfield myTextField = new JTextField();
myTextField.setText("Hello world");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...