JavaFx:标签文本宽度

时间:2018-05-24 10:09:11

标签: java javafx label javafx-8

我的Label宽度有问题。如果我改变窗口的大小并且标签的宽度不适合窗口。

我期待的是:

初始值:012345678901234567890123456789

调整大小后:01234567890123 ...

但实际状态:

Initial state

调整大小后:

After resize

如何获得预期结果?

以下是.fxml文件

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<AnchorPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="stackoverflow.labeltest.Controller">
    <HBox>
        <Label fx:id="label"/>
    </HBox>
</AnchorPane>

1 个答案:

答案 0 :(得分:1)

AnchorPane不会在没有约束的情况下调整孩子的大小。您需要设置rightAnchor的{​​{1}}和leftAnchor约束。 (您也可以简单地以root身份使用HBox。)

HBox
相关问题