I use three buttons to display each child panel in stackpane,but when I click the button,it displays different panels per click
Example
btn0-> pane 0,pane 1and pane 2
btn1-> pane 0,pane 1and pane 2
btn2-> pane 0,pane 1and pane 2
I just want it to display a specific panel for specific buttons in java swing cardLayout should I do?
btn0-> pane 0
btn1-> pane 1
btn2-> pane 2
Please help me!
@FXML
void btn0(ActionEvent event) {
stackConsole.getChildren().get(0).toFront();
}
@FXML
void btn1(ActionEvent event) {
stackConsole.getChildren().get(1).toFront();
}
@FXML
void btn2(ActionEvent event) {
stackConsole.getChildren().get(2).toFront();
}
Depending on your needs you may be interested in the
TabPane
class.Of course implement similar funtionality in the controller class. Calling
toFront()
for a child will not have the desired effect however, sincestackConsole
toFront
just moves theNode
it is called for to the last child position of the parent.What you're trying to achieve however seems to be replacing the children of
stackConsole
. This can be done by injecting the different children to the controller class and usingObservableList.setAll
to replace the contents. The<fx:define>
tag can be used for children not initially shown in the scene.Example
FXML
Controller