new line in TextBox (JavaFX 2.0)

你离开我真会死。 提交于 2019-12-21 21:23:19

问题


I'm trying to create TextBox with JavaFX 2.0. My source is following:

TextBox textBox = new TextBox();
textBox.setPrefSize(150, 600);
textBox.setText("Hello\n world!");

Result is:

How could I create new line in TextBox?


回答1:


Creating a multilined TextBox is a JavaFX 1.3 feature. In JavaFX 2.0 you have to use a TextArea.

TextArea textArea = new TextArea();
textArea.setPrefRowCount(2);            
textArea.setText("Hello\nworld!");

The JavaFX UI Controls tutorial does not mention the TextArea control. Maybe they missed something. As you can see in this JavaFX 1.3 TextBox tutorial the TextBox had a 'multiline' and a 'lines' property. JavaFX 1.3 did not have a TextArea.



来源:https://stackoverflow.com/questions/6723506/new-line-in-textbox-javafx-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!