java - 如何在文本字段中设置下一行

标签 java user-interface javafx

所以我用一个 Gui 创建了一个聊天,其中包含一些男人的照片,这些男人的照片上方有一个文本字段,其中包含该人聊天的文本。

这是迄今为止我创建的最难的项目,我对自己的成就感到非常自豪,我已经为我的聊天客户端创建了一个多线程服务器和协议(protocol):)如果文本进入,我从 Stackoverflow 找了一个人来帮助我调整文本字段的大小它比文本字段的大小大:)但是现在当文本字段调整大小时我遇到了另一个问题,它只调整宽度,因为我的文本字段不会更改行

我创建了以下代码来尝试更改行,但它似乎不起作用,有人可以帮助我吗?

Send.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {

            String x = textField_chat.getText();
            if (x.length() > 10) {
                String oldLine = x.substring(0,5);

             String newLineString = x.substring(5,x.length());
             txt_ChatPerson1.setText(oldLine+"\n"+newLineString);
            }else {


            textField_chat.setText("");
            txt_ChatPerson1.setVisible(true);
            txt_ChatPerson1.setText(x);
        }

最佳答案

使用 TextArea相反。

来自 javadoc 的 TextArea 描述:

Text input component that allows a user to enter multiple lines of plain text. Unlike in previous releases of JavaFX, support for single line input is not available as part of the TextArea control, however this is the sole-purpose of the TextField control. Additionally, if you want a form of rich-text editing, there is also the HTMLEditor control.

关于java - 如何在文本字段中设置下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12750032/

相关文章:

java - 在javafx的选择对话框中查找点击了哪个按钮

java - 自动滚动 JavaFX TextFlow

JavaFX:设置场景最小尺寸,不包括装饰

java - 使用 setter 方法或直接引用构造函数中的变量?

qt - 为什么我没有 Qt Gui Application 选项?

c# - 动态创建窗口时按钮居中对齐

Python Gui 编程和 CPU 使用。如何创建 'idle' 或 'throttle' 以便一段代码不会消耗 100 个可用 cpu?

java - 如何将多个 MouseListener 添加到单个 JFrame?

java - SeekBar 指针不在中心 Android Studio Java

java - 如何将包含特殊字符的小数点后两位数字的字符串数字四舍五入?