【问题标题】:How to align text vertically in JavaFX?如何在 JavaFX 中垂直对齐文本?
【发布时间】:2018-03-28 15:59:26
【问题描述】:

我在JavaFX 中有TextArea。我需要垂直对齐文本或使TextArea 与内容大小相同。目前,TextArea 正在增长以填充其父级高度。

【问题讨论】:

标签: javafx textarea


【解决方案1】:

我通过创建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 边框并将其居中。这样我得到了居中的文本,也可以选择。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-22
    • 2014-11-03
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多