如何设置 JavaFX TextArea 的高度和宽度?

4
TextArea txt = new TextArea();

我该调用哪个方法来设置这个 TextArea 的高度和宽度?

3
setPrefColumnCount()setPrefRowCount() 应该能够满足您的需求。请参阅此处 - Draken
谢谢,那个起作用了。 - HashTables
3个回答

10
TextArea textArea = new TextArea(); //making a TexrArea object
double height = 400; //making a variable called height with a value 400
double width = 300;  //making a variable called height with a value 300

//You can use these methods
textArea.setPrefHeight(height);  //sets height of the TextArea to 400 pixels 
textArea.setPrefWidth(width);    //sets width of the TextArea to 300 pixels

1
请考虑在您的答案中添加一些细节和解释,以支持您的回答,从而帮助他人。 - Souvik Ghosh

5

setPrefColumnCount() 和 setPrefRowCount() 工作正常。


2
更好的是:
TextArea textArea = new TextArea();
double prefWidth = 1.0
double prefHeight = 1.0
textArea.setPrefSize(prefWidth, prefHeight);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接