0

facing Difficulties to create multiple scenes in a single stage.

this is the init method where i've loaded two images.

    public void init() {


        Rotate rotate=new Rotate();
                rotate.setAngle(0.0);
                rotate.setPivotX(1000/2);
                rotate.setPivotY(1020/2);


                Image img=new Image("file:///C:/Users/Avi/Desktop/test.jpg");
                ImageView view=new ImageView(img);
                Image back=new Image("file:///C:/Users/Avi/Desktop/background.jpg");
                ImageView backview=new ImageView(back);
                view.setOpacity(0.25);
                view.setX(1000/2);
                view.setY(1020/2);

        sp_mainlayout = new StackPane();  
                backlay=new StackPane();
        cc_custom = new CustomControl();
                sp_mainlayout.getChildren().add(backview);
                sp_mainlayout.getChildren().add(view);
        sp_mainlayout.getChildren().add(cc_custom);
                backlay.getChildren().add(backview);      
    }

Now in the start method the stage is single but i want to show one image at the background at a large size and the other one in front of it in a smaller size. But two scenes aren't working together. Need some modification for the code.(the sizes of the scenes will be different)


    public void start(Stage primaryStage) throws Exception {


        primaryStage.setTitle("Chess game");

                Scene scene1 =new Scene(sp_mainlayout,800,600);
        primaryStage.setScene(scene1);
                primaryStage.show();

                Scene scene =new Scene(backlay,800,600);
        primaryStage.setScene(scene);


        primaryStage.setMinWidth(300);
        primaryStage.setMinHeight(300);
                primaryStage.setResizable(false);
                primaryStage.show();

    }

  • A `Stage` can only ever have one `Scene`. You can _switch_ scenes, but you can't have both of them showing at the same time (unless you use two different stages). However, why not use one scene the proper layouts? The aptly named `StackPane` layout will _stack_ its children on top of each other. – Slaw Jul 16 '19 at 21:07
  • Yeah, tried that and the StackPane layout stacks its children. But the underneath child is not working. :( – avishak chakroborty Jul 16 '19 at 22:10
  • Possible duplicate of [Mouse Events get Ignored on the Underlying Layer](https://stackoverflow.com/questions/24607969/mouse-events-get-ignored-on-the-underlying-layer) – Zephyr Jul 16 '19 at 22:45
  • what if i want the scenes of different sizes? – avishak chakroborty Jul 17 '19 at 05:46

0 Answers0