Is there a way to get a reference to Tab
or TabPane
without no improvised way if you have reference to only the Node
inside the Tab
for eg
TabPane tabPane = new TabPane();
Tab tab = new Tab();
tab.setText("new tab");
Rectangle drect = new Rectangle(200,200, Color.LIGHTSTEELBLUE);
tab.setContent(drect);
tabPane.getTabs().addAll(tab,new Tab("tab 2"));
assume i only have reference to drect
how can i get tab
.
I am not interested in Node.setUserData()
also drect.getParent().getClass().getName()
returns
TabPaneSkin
anon inner class TabContentRegion
: two strangers.
All i am trying to say is Node.getParent()
should return the parent Node
, general uni-knowledge ( node's representation in the scene graph can be traced with getParent() ), but, when it comes to Tab
s its all wrong, hence my question
EDIT
Why i needed this, suppose you have TabPane
consisting of soo many Tab
, in one particular Tab
you have a TreeView
s as its Node-Content
which is selected out of some conditions, and for that particular TreeView
you have different Custom Cell
s because its TreeItem
s differ in UI and function- like changing styles
binding Fonts
& other bindables and Animating Tab
hiding other Tab
s in the TabPane
, closing other Tab
s
with this scenario following this approach seems legit for me as, you do not do unnecessary stuff, like exposing children to bad weather. :-)
Thanks Sir James_D
I know this is a little old question, but I will post the solution for someone how is still struggling with this issue.
The following is the FXML structure example of the
TabPane
.The following method returns the
Tab
object which includes theNode
specified as an argument.Get the
TabPane
object and the tab content area of theTab
object fromNode
object.Scan all
Tab
objects who are contained in theTabPane
(that is retrieved in the phase #1).Tab
object whose content area is equivalent to the tab content area (that is retrieved in the phase #1).The simpler way is shown below.
The
Tab
itself is not aNode
, so you can't get the tab just by iterating through the scene graph in any way. You can get to theTabPane
if you go up far enough in the hierarchy. For example:will return the nearest
TabPane
containing the node passed in, ornull
if the node is not in a tab pane.However, needing this just seems like your design is wrong. If you put a node in a tab pane, at some point you create a tab, so you should just organize your code so you have the reference to the tab available.