简体   繁体   中英

How to set height and width of JavaFX TextArea?

TextArea txt = new TextArea();

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

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

setPrefColumnCount() 和 setPrefRowCount() 有效

Even better:

TextArea textArea = new TextArea();
double prefWidth = 1.0
double prefHeight = 1.0
textArea.setPrefSize(prefWidth, prefHeight);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM