Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When adding a second item to my stackpane, the first item loses its Event/MouseOn. Why? How can I fix? JavaFX

I have a stackpane. When I add a second item to my stack pane, both show up, but I can't click on my first item anymore. It becomes 'unclickable'.

what ever I defined in my .setonmouse does not work. It works for my second item. If I switch the order they are in the stack pane, the other one works, but not both.

is there a fix for this? This is what my program looks like:

I want my 'grid' centered ALWAYS. There are buttons to the left centered in a column, there will be buttons on the right later on, and there will be buttons/Text on top of the grid and buttom in the margins later on too.

I want everything to be clickable.

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

like image 353
CREW Avatar asked Mar 27 '12 23:03

CREW


1 Answers

StackPane orders items in Z-order: latter above the former. So, your second item gots all mouse clicks and first one (being covered by second) doesn't get anything.

For layout you've described 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();
}
like image 178
Sergey Grinev Avatar answered Oct 01 '22 08:10

Sergey Grinev