问题
I'm developing an app in JAVAFX. Mainly, the app is using a TabPane
controller. In the first tab, i'm loading a controller for a StackPane
. In the StackPane
i'm loading as a default, one list view with custom cells. In each cell i'm having some buttons. I want to add a new pane in the stack pane and bring it to front when a button is clicked.
I tried with the toFront()
and toBack()
but i can't get anything working.
I've check, and both panes are loaded and their content is the right one.
I can't attach photos because i don`t have enough rep.
Any suggestion is appreciated.
回答1:
It's hard to know exactly what's going wrong since you didn't post any code, but from the StackPane Javadocs:
The z-order of the children is defined by the order of the children list with the 0th child being the bottom and last child on top. If a border and/or padding have been set, the children will be layed out within those insets.
So to move a Node
to the front, you should move it to the end of the list:
StackPane stackPane = ... ;
Node node = ... ;
// move node to front:
// remove node from current location in child list"
stackPane.getChildren().remove(node);
// add node back in at end of child list:
stackPane.getChildren().add(node);
来源:https://stackoverflow.com/questions/26710777/javafx-tabpane-with-stackpane-and-custom-controls