2011-07-17 55 views
2

我正在嘗試使用JavaFX 2.0創建TextBox。 我的來源如下:TextBox中的新行(JavaFX 2.0)

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

結果是:

enter image description here

我怎麼能創造TextBox新的生產線?

回答

4

創建多線TextBox是JavaFX 1.3的一個特性。在JavaFX 2.0中,你必須使用TextArea。

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

JavaFX UI Controls教程沒有提到TextArea控件。也許他們錯過了什麼。正如你在這篇JavaFX 1.3 TextBox教程中看到的,TextBox有一個'多行'和'行'屬性。 JavaFX 1.3沒有TextArea。