When you add a second item to the stack stack, the first item loses Event / MouseOn. What for? How can i fix it? Javafx

I have a stack. When I add a second item to the stack stack, both are displayed, but I can no longer click on my first item. He becomes "invisible."

what i defined in my .setonmouse does not work. He works for my second subject. If I switch the order that they are on the stack, the other one works, but not both.

is there a fix This is my program as follows:

I want my "grid" to be ALWAYS focused. There are buttons on the left centered in the column, on the right there will be buttons on the right, as well as buttons / Text over the grid and buttom in the fields later.

I want everything to be clickable.

http://img688.imageshack.us/img688/6025/examplerg.png

+4
source share
2 answers

StackPane orders items in Z-order: the last is higher than the first. Thus, your second item gets all the mouse clicks, and the first (covered by the second) gets nothing.

To describe the layout, you can use BorderPane:

 public void start(Stage stage) throws Exception { BorderPane root = new BorderPane(); root.setCenter(new Rectangle(100,100, Color.RED)); root.setLeft(new Rectangle(10,10, Color.BLUE)); root.setRight(new Rectangle(10,10, Color.CYAN)); stage.setScene(new Scene(root,300,300)); stage.show(); } 
+4
source

You can make any transparent "transparent" panel so that it does not consume any click events and does not pass them onto the stack under it.

Here is an example code ... this example sets 4 stacks on the stack, and it just starts from the moment you press the mainPane button.

 StackPane rootPane = new StackPane(); VBox mainPane = new VBox(80); BorderPane helpOverlayPane = new BorderPane(); helpOverlayPane.setMouseTransparent(true); Canvas fullScreenOverlayCanvas = new Canvas(); fullScreenOverlayCanvas.setMouseTransparent(true); VBox debugPane = new VBox(); debugPane.setAlignment(Pos.BASELINE_RIGHT); AnchorPane debugOverlay = new AnchorPane(); debugOverlay.setMouseTransparent(true); debugOverlay.getChildren().add(debugPane); AnchorPane.setBottomAnchor(debugPane, 80.0); AnchorPane.setRightAnchor(debugPane, 20.0); rootPane.getChildren().addAll(mainPane, fullScreenOverlayCanvas, debugOverlay, helpOverlayPane); 

Now that you want to use your canvas to paint on top, make sure that you change the mouse transparency to false only for this stack and keep all the panels on top of the transparent mouse.

 fullScreenOverlayCanvas.setMouseTransparent(false); debugOverlay.setMouseTransparent(true); fullScreenOverlayCanvas.setVisible(true); doSomethingWithCanvasThatNeedsMouseClicks(); 

PS I did some editing of the code that I had, so it may not work as it is. Also, see the discussion on how to make only parts of panels transparent: JavaFX Pass MouseEvents through a transparent Node for children

+4
source

Source: https://habr.com/ru/post/1403779/


All Articles