【发布时间】:2014-01-03 10:10:44
【问题描述】:
我创建了一个自定义组件 PlayerEditableRow,并将其放置在一个锚窗格 PlayersTable 中,该窗格位于一个选项卡 PlayersTab 中,但我的可编辑行组件不是交互式的。例如,我有一个按钮和组合框,当我单击它们时它们没有响应。 PlayersTable 也不响应鼠标单击侦听器。但是,当我将可编辑行放在 PlayersTab 锚窗格中时,自定义组件确实有效。这是我的 GUI 的设置:
标签控制器:
public class PlayersTab extends Tab implements IObserver {
@FXML private AnchorPane content;
@FXML private PlayersTable playerTable;
private void initView() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("players_tab.fxml"));
fxmlLoader.setRoot(content);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (Exception e) {
e.printStackTrace();
}
this.setText("Players");
this.setContent(content);
playerTable.initializeController(gameSettings);
}
fxml 文件:
<?import dominion.application.controller.PlayersTable?>
<fx:root type="javafx.scene.layout.AnchorPane" fx:id="content" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
<HBox prefHeight="100.0" prefWidth="200.0" spacing="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<VBox fx:id="playersVBox" prefHeight="-1.0" prefWidth="-1.0" spacing="10.0" HBox.hgrow="SOMETIMES">
<children>
<Label text="Players" >
<font>
<Font size="18.0" />
</font>
<VBox.margin>
<Insets />
</VBox.margin>
</Label>
<PlayersTable fx:id="playerTable" />
</children>
</VBox>
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
</children>
</fx:root>
自定义组件:
public class PlayersTable extends AnchorPane implements IObserver {
@FXML private VBox playerTable;
private void initView() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("players_table.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (Exception e) {
e.printStackTrace();
}
playerTable.getChildren().add(new PlayerEditableRow(PlayerType.COMPUTER, gameSettings));
}
fxml 文件:
<fx:root type="javafx.scene.layout.AnchorPane" id="AnchorPane" blendMode="DARKEN" maxHeight="-1.0" maxWidth="-1.0" minHeight="-1.0" minWidth="-1.0" mouseTransparent="true" prefHeight="-1.0" prefWidth="-1.0" style="" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
<VBox fx:id="playerTable" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" style="" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</fx:root>
我需要做什么才能使我的自定义组件具有交互性?在我使用相互嵌套的自定义选项卡窗格和自定义锚窗格之前,我没有遇到过这个问题。
这是我的非活动组件的图像:
【问题讨论】:
-
我也有同样的问题。你找到解决办法了吗?
-
不,在我找到修复之前,我只是删除了额外的锚窗格并将所有内容放在选项卡视图中。
标签: java user-interface javafx javafx-2 custom-component