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

问题描述

我想制作一个Swing程序,用于编写已完成内容的更新。它将所有信息写入不可编辑的 JTextField

I want to make a Swing program that writes updates on what you have done. It writes all the information on an uneditable JTextField.

例如:

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

问题在于我无法将两条线分开。

The problem is that I can't make the two lines separate.

我得到的是:

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

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

What I've tried is this: (This does not work)

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来实现这个目的,代码也没有太大的不同,你仍然可以使用相同的代码,或者你可以

you can't have multiple lines with JTextField , you can use JTextArea for that purpose , and the code wouldn't be much different too , you can still use the same code or you can just

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

其中TF_Betinfo是JTextArea而不是JTextField。

where TF_Betinfo is a JTextArea rather than a JTextField .

这篇关于如何在JTextField中创建一个新行来输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 16:05