我正在尝试删除TextArea Vertical ScrollBar。 TextArea自动递增其高度而不显示垂直ScrollBar,但它(垂直ScrollBar)在五行键入后重新出现。我怎样才能完全删除它?
public class TextAreaAutoResizable {
private final Text textHolder = new Text();
private double oldHeight = 0;
public void resize(TextArea textArea) {
textArea.setPrefSize(200, 40);
textArea.setWrapText(true);
textHolder.textProperty().bind(textArea.textProperty());
textHolder.layoutBoundsProperty().addListener(new ChangeListener<Bounds>() {
@Override
public void changed(ObservableValue<? extends Bounds> observable, Bounds oldValue, Bounds newValue) {
if (oldHeight != newValue.getHeight()) {
System.out.println("newValue = " + newValue.getHeight());
oldHeight = newValue.getHeight();
textArea.setPrefHeight(textHolder.getLayoutBounds().getHeight() + 20); // +20 is for paddings
}
}
});
textHolder.setWrappingWidth(textArea.getWidth() - 10);
}
}