发布于 2016-04-30 03:59:06
Oracle上有一个归档讨论,它建议将节点封装在ScrollPane中并在ScrollPane上设置工具提示。虽然这并不理想,因为它为场景图添加了一个不必要的节点,但更重要的是,并不是所有场景都能很好地工作。考虑将工具提示添加到TitledPane的图形中
<TitledPane text="My TitledPane" fx:id="someTitledPane" expanded="true" contentDisplay="RIGHT">
<graphic>
<ScrollPane fitToWidth="true" fitToHeight="true" style="-fx-background-color: rgba(255, 255, 255, 0);">
<ImageView fitWidth="24.0" fitHeight="24.0" preserveRatio="true" pickOnBounds="true">
<image>
<Image url="/images/questionMark.jpg" />
</image>
</ImageView>
<tooltip>
<Tooltip text="My tooltip."/>
</tooltip>
</ScrollPane>
</graphic>
<Label text="Hello!"/>
</TitledPane>尽管ScrollPane有一个透明的背景,但在问号图形后面仍然有一个可见的白色框:

有一个解决方法,那就是利用<fx:script>的力量
<?language javascript?>
<TitledPane text="My TitledPane" fx:id="someTitledPane" expanded="true" contentDisplay="RIGHT">
<graphic>
<ImageView fx:id="questionMarkImageView" fitWidth="24.0" fitHeight="24.0" preserveRatio="true" pickOnBounds="true">
<image>
<Image url="/images/questionMark.jpg" />
</image>
</ImageView>
<fx:script>
var tooltip = new javafx.scene.control.Tooltip('My tooltip');
javafx.scene.control.Tooltip.install(questionMarkImageView, tooltip);
</fx:script>
</graphic>
<Label text="Hello!"/>
</TitledPane>请注意,fx:id of ImageView是在脚本中引用的(我在任何地方都没有看到这个功能,只是通过实验才发现的--这实际上促使我发布这个Q&A,希望其他人会发现它有用)。结果如下:

https://stackoverflow.com/questions/36950542
复制相似问题