我想制作一个Swing程序,以编写有关您所做的更新。它将所有信息写在不可编辑的JTextField上。

例如:

You have changed the text to BLUE.
You have changed the text to RED.


问题是我无法将这两行分开。

我得到的是:

You have changed the text to BLUE. You have changed the text to RED.


我已经尝试过的是:(这不起作用)

TF_BetInfo.setText(TF_BetInfo.getText() + "\nYou have changed the text to BLUE.");
TF_BetInfo.setText(TF_BetInfo.getText() + "\nYou have changed the text to RED.");

最佳答案

您不能在JTextField中使用多行代码,可以使用JTextArea来实现此目的,并且代码也没有太大不同,您仍然可以使用相同的代码,也可以

TF_BetInfo.append("\nyou have ...... ");


其中TF_Betinfo是JTextArea而不是JTextField。

关于java - 如何在JTextField中创建新行以键入?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27698592/

10-09 05:48