0
在JavaFX我试图阻止标签重叠的父母。这发生在父级调整为比标签更低的大小时。在这种情况下,我期望标签开始隐藏起来,但它只是稍微显示了父项的边界。JavaFX停止标签重叠父项?
您可以使用以下FXML测试了这一点:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane minHeight="500.0" minWidth="500.0" prefHeight="500.0" prefWidth="558.0" style="-fx-background-color: black;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65">
<children>
<AnchorPane layoutX="110.0" layoutY="102.0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: red;" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="15.0">
<children>
<Label alignment="CENTER" layoutX="238.0" layoutY="201.0" style="-fx-background-color: gray;" text="Testing to see if this overlaps" textFill="WHITE" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0">
<font>
<Font size="37.0" />
</font>
</Label>
</children>
</AnchorPane>
</children>
</AnchorPane>
注意添加底部锚标签会解决这个问题,但我想不使用。有没有解决这个问题?谢谢。