-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
None
-
None
The getChildren() method of Parent is protected. So if I create a subclass of Parent called MyParent, only MyParent itself can add child nodes to itself. This has a number of design limitations as explained in the following.
The protected getChildren() method makes it difficult to create UI controls which are capable of displaying themselves as a child of any node. As an example, let's say I have created a class ColorPaletteDialog which presents the user with a number of colors to choose from. I would like to be able to use this ColorPaletteDialog in many places, so the dialog should be able to pop up as a child node of many different nodes. However, there is no common Java FX interface which I can pass to ColorPaletteDialog to allow it to add itself as a child of another node. If I pass an instance of Parent to ColorPaletteDialog, the dialog cannot invoke Parent.getChildren().add(this) because the getChildren() method is protected.
Now consider a common use case for ColorPaletteDialog. Let's say I have three Node classes A, B, and ColorPaletteDialog. Imagine a mouse click event occurs in class A, and now A wants to display a new ColorPaletteDialog inside B. Class A cannot tell ColorPaletteDialog that it should show up inside B, because ColorPaletteDialog cannot invoke B.getChildren().add(this), since the getChildren() method of B is protected. Moreover, A cannot itself add ColorPaletteDialog to B, because A cannot invoke the protected getChildren() method of B either. This means that in order to show a ColorPaletteDialog as a child of B, Java FX requires that B should know of ColorPaletteDialogs in advance and expose an addColorPaletteDialog or public getPublicChildren() method.
Since B could be a class from a third party API, there is no guarantee, that B will have such methods. Hence there are many situations where you cannot add additional child nodes to a node.
I know that Swing is not a perfect UI API, but it actually makes it quite easy to create special controls which can be added anywhere. I think Java FX should have this capability too.
The protected getChildren() method makes it difficult to create UI controls which are capable of displaying themselves as a child of any node. As an example, let's say I have created a class ColorPaletteDialog which presents the user with a number of colors to choose from. I would like to be able to use this ColorPaletteDialog in many places, so the dialog should be able to pop up as a child node of many different nodes. However, there is no common Java FX interface which I can pass to ColorPaletteDialog to allow it to add itself as a child of another node. If I pass an instance of Parent to ColorPaletteDialog, the dialog cannot invoke Parent.getChildren().add(this) because the getChildren() method is protected.
Now consider a common use case for ColorPaletteDialog. Let's say I have three Node classes A, B, and ColorPaletteDialog. Imagine a mouse click event occurs in class A, and now A wants to display a new ColorPaletteDialog inside B. Class A cannot tell ColorPaletteDialog that it should show up inside B, because ColorPaletteDialog cannot invoke B.getChildren().add(this), since the getChildren() method of B is protected. Moreover, A cannot itself add ColorPaletteDialog to B, because A cannot invoke the protected getChildren() method of B either. This means that in order to show a ColorPaletteDialog as a child of B, Java FX requires that B should know of ColorPaletteDialogs in advance and expose an addColorPaletteDialog or public getPublicChildren() method.
Since B could be a class from a third party API, there is no guarantee, that B will have such methods. Hence there are many situations where you cannot add additional child nodes to a node.
I know that Swing is not a perfect UI API, but it actually makes it quite easy to create special controls which can be added anywhere. I think Java FX should have this capability too.