喂,
我有以下问题。
是否可以创建一个主fxml文件并放置/包含另一个具有用户定义属性的fxml文件。
例如,我有:main.fxml和fan_object.fxml
然后将3 fan_object.fxml包含到main.fxml上。现在,我想为每个fan_object.fxml实例定义另一个地址或工具提示文本,等等。
这个是可能的吗?
发布于 2018-11-23 10:02:00
签入文档:fx:包括
你能做的是:
如果这是您的main.fxml
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox xmlns:fx="http://javafx.com/fxml">
<children>
<fx:include fx:id="fan1" source="fan_object.fxml"/>
<fx:include fx:id="fan2" source="fan_object.fxml"/>
<fx:include fx:id="fan3" source="fan_object.fxml"/>
</children>
</VBox>在您的MainController.java类中:
@FXML
private FanController fan1Controller;
@FXML
private FanController fan2Controller;
@FXML
private FanController fan3Controller;现在在您的FanController.java类中:
public void setToolTip (String tooltipText){
//You put the tooltip of the object you have in this controller
//for instance
myButton.setTooltip(new Tooltip(tooltipText));
}现在你要做的就是打电话:
fan1Controller.setToolTip("Tip : !");希望这能解决你的问题。
https://stackoverflow.com/questions/53444046
复制相似问题