Answer the question
In order to leave comments, you need to log in
Is it possible to change containers (layers) on button click, working in JavaFX?
The Stage consists of a BorderPane , which in turn consists of 2 Splitpanes . So, is it possible when you click on the button (it is in SplitPane1) to make the second Splitpane change to another container with ready-made nodes.
Answer the question
In order to leave comments, you need to log in
can.
If the button is normal, then here is the base.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
* Created by Evgeny on 18.03.2016.
*/
public class Example extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane borderPane = new BorderPane();
SplitPane splitPane1 = new SplitPane();
Button button_changeContainer = new Button("Изменить контейнер");
splitPane1.getItems().add(button_changeContainer);
SplitPane splitPane2 = new SplitPane();
splitPane2.getItems().addAll(new Label("Первый"),new Label("Контейнер"), new Label("SplitPane"));
VBox vBox = new VBox();
vBox.getChildren().addAll(new Label("Второй"),new Label("Контейнер"), new Label("VBox"));
borderPane.setCenter(splitPane1);
borderPane.setRight(splitPane2);
button_changeContainer.setOnAction(new EventHandler<ActionEvent>() {
boolean firstOrSecond = true;
@Override
public void handle(ActionEvent event) {
firstOrSecond = !firstOrSecond;
if(firstOrSecond){
borderPane.setRight(splitPane2);
}
else borderPane.setRight(vBox);
}
});
primaryStage.setScene(new Scene(borderPane));
primaryStage.setWidth(600);
primaryStage.setHeight(600);
primaryStage.show();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question