如何在 JavaFX 中垂直对齐文本?
How to align text vertically in JavaFX?
我在 JavaFX
中有 TextArea
。我需要垂直对齐文本或使 TextArea
与内容大小相同。目前,TextArea
正在增长以填充其父级高度。
我通过创建 Label
对其进行排序,将其放在 TextArea
后面,使其不可见(以防万一)并将 TextArea 高度绑定到标签:
@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()));
}
通过样式摆脱 TextArea
边框并将其居中。这样我就得到了居中的文本,也可以选择。
我在 JavaFX
中有 TextArea
。我需要垂直对齐文本或使 TextArea
与内容大小相同。目前,TextArea
正在增长以填充其父级高度。
我通过创建 Label
对其进行排序,将其放在 TextArea
后面,使其不可见(以防万一)并将 TextArea 高度绑定到标签:
@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()));
}
通过样式摆脱 TextArea
边框并将其居中。这样我就得到了居中的文本,也可以选择。