Skip to content
Advertisement

How to force control skin to be created so I can use getParent?

In the following minimal example when the parents of tabs and tabs2 are printing out, they are both null.

From this question I’ve come to understand because while the two TabPanes have been added to the SplitPane, because the skin of the TabPanes hasn’t been created yet, getScene and getParent will return null.

So the question is, how can I get access to their parents at the point in code where I am trying to print it out? I presume I need to force the creation of the skin?

JavaScript

Advertisement

Answer

May be instead of trying to rely on the node rendering, you can consider trying to change your logic by keeping references to parent nodes. That way you dont need to rely on node rendering.

Below are the changes i tried and it works as expected.

#Change 1:

Add the below instance variable to DetachableTabPane.java, to let know in which split pane this is set. That way you dont need to loop through all the nodes, to find the parent SplitPane.

JavaScript

#Change 2:

Create a custom SplitPane that register itself to its children. So you dont need to worry to set it everytime when you add a DetachableTabPane to SplitPane.

JavaScript

# Change 3:

Update the placeTab method as below. This way you directly deal with the SplitPane instance associated to the DetachableTabPane and not worrying about when the node(s) will be rendered.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement