java 如何设置javafx TextArea的高度和宽度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37458555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:31:32 来源:igfitidea点击:
How to set height and width of javafx TextArea?
提问by HashTables
TextArea txt = new TextArea();
What method do i call to set the height and width of this textarea?
我调用什么方法来设置这个textarea的高度和宽度?
回答by Michael Cenzoprano
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
回答by HashTables
setPrefColumnCount() and setPrefRowCount() worked
setPrefColumnCount() 和 setPrefRowCount() 有效
回答by Daniel
Even better:
更好的是:
TextArea textArea = new TextArea();
double prefWidth = 1.0
double prefHeight = 1.0
textArea.setPrefSize(prefWidth, prefHeight);