brc*_*low 7 javafx tooltip fxml
在JavaFX中,Control的子类有一个tooltip属性,这意味着可以使用FXML以声明方式添加Tooltip:
<CheckBox fx:id="someCheckBox" mnemonicParsing="false" text="Do It?">
<tooltip>
<Tooltip text="Whether or not to do it."/>
</tooltip>
</CheckBox>
Run Code Online (Sandbox Code Playgroud)
这是可能的,因为CheckBox是Control的子类.
但是,我希望能够使用FXML向任何场景图节点添加工具提示(即无需使用Java以编程方式添加工具提示).
有一个存档的讨论上建议包裹在Oracle社区论坛节点 A的内部滚动窗格和设置上滚动窗格的工具提示.这不太理想,因为它为场景图添加了不必要的节点,但更重要的是在所有场景中都不能很好地工作.考虑尝试将工具提示添加到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>
Run Code Online (Sandbox Code Playgroud)
即使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>
Run Code Online (Sandbox Code Playgroud)
请注意,fx:idImageView的内容是在脚本内部引用的(我没有在任何地方看到此功能,只能通过实验找到它 - 这实际上促使我发布此问答,希望其他人发现它有用).结果如下:
| 归档时间: |
|
| 查看次数: |
4690 次 |
| 最近记录: |