0

I have TextArea in JavaFX. I need to align text vertically or make TextArea to be same size as content. Currently, TextArea is growing to fill its parent height. enter image description here

Alyona
  • 1,682
  • 2
  • 21
  • 44

1 Answers1

0

I sorted it by creating a Label, placing it behind TextArea, making it invisible(just in case) and binding TextArea height to label:

@FXML
private TextArea msg;

@FXML
private Label bindingText;

@FXML
private Button button; 


@FXML
private void initialize() {
    bindingText.textProperty().bind(msg.textProperty());
    msg.setText(Word.customTranslate("data_transfer_failed", Locale.getDefault().getLanguage()));
    msg.prefHeightProperty().bind(bindingText.heightProperty());
    button.setText(Word.customTranslate("close_app", Locale.getDefault().getLanguage()));
    }

Get rid of TextArea borders through styling and center it. This way I got centered text, that can also be selected. enter image description here

Alyona
  • 1,682
  • 2
  • 21
  • 44