您好我已经制作了一个javafx应用程序,在TabPane.Application中加载了新标签,除了新标签按钮,TextFields不起作用以及tablane的切换无法正常工作时运行良好。
FXML
<GridPane id="content" alignment="CENTER" prefHeight="310.0" prefWidth="800.0" styleClass="mainParent" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gvj.sndp.view.controller.HomeController">
<children>
<SplitPane dividerPositions="0.18421052631578946" prefHeight="160.0" prefWidth="200.0" GridPane.rowIndex="2">
<items>
<TreeView fx:id="menuTreeView" prefHeight="273.0" prefWidth="115.0" />
<TabPane fx:id="tabPane" mouseTransparent="true" prefHeight="200.0" prefWidth="200.0" rotateGraphic="true" />
</items>
</SplitPane>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" GridPane.rowIndex="1">
<children>
<JFXButton buttonType="RAISED" onAction="#addMemberSelect" prefHeight="33.0" prefWidth="37.0" text="AM">
<opaqueInsets>
<Insets />
</opaqueInsets>
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</JFXButton>
<JFXButton buttonType="RAISED" onAction="#addSelfHelpSelect" prefHeight="33.0" prefWidth="55.0" text="ASH">
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</JFXButton>
<JFXButton onAction="#addOfficeBarrierSelect" prefHeight="35.0" prefWidth="43.0" text="AOB">
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</JFXButton>
</children>
</HBox>
<HBox />
</children>
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="-1.0" prefWidth="-1.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="35.0" minHeight="22.0" prefHeight="30.0" valignment="CENTER" vgrow="ALWAYS" />
<RowConstraints maxHeight="35.0" minHeight="22.0" prefHeight="22.0" valignment="CENTER" vgrow="ALWAYS" />
<RowConstraints valignment="CENTER" vgrow="ALWAYS" />
</rowConstraints>
</GridPane>
当用户单击该按钮时,将创建一个新选项卡并将其加载到TabPane。 为什么不工作。我做错了什么?
控制器
@FXML
private TabPane tabPane;
@FXML
private void addMemberSelect() {
App.getInstance().showProgressIndicator(myController);
Task<FXMLLoader> task = new Task<FXMLLoader>() {
@Override
protected FXMLLoader call() throws Exception {
return new FXMLLoader(App.class.getResource(Screens.ADD_MEMBER));
}
@Override
protected void succeeded() {
super.succeeded();
Tab tabA = new Tab("Add Member");
final ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
try {
scrollPane.setContent(get().load());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
tabA.setContent(scrollPane);
tabPane.getTabs().add(tabA);
App.getInstance().hideProgressIndicator(myController);
}
@Override
protected void failed() {
super.failed();
App.getInstance().hideProgressIndicator(myController);
}
};
new Thread(task).start();
}