On Mon, 16 Aug 2021 08:22:35 GMT, Pankaj Bansal <pban...@openjdk.org> wrote:
> A container may include few default components as children, which are added > to it during creation. Due to this, calling function getChildrenCount on a > new created instance may return non zero value. This behaviour may vary > according to L&F also, as some L&F may add some default components to a > container, but other L&F may choose not to do so. > > The current bugs reports that this behaviour looks suspicious as it is > expected that a newly created container will have zero children. > > Current specification is not clear on this whether it is allowed for a > container to contain default components or not. The fix make changes to the > specification to clarify the same. > > Note: I think this will need a CSR, I will file one after the review is > completed > > I wonder how the other components handle that. For example, the JComboBox > > in Aqua L&F is a "compound" element and it contains a text field and > > button, what does the "getComponentCount" return in that case, wIll we hide > > internal data from the user? > > I just ran the following test for JComboBox for all L&Fs on my Mac. It fails > for everyone of them. The test and output is as below. Looks like this test > is not being run for all components for all L&Fs. It should give lot of > failures I guess. Yep not unexpected which is why I said this needed to be documented at least as high up as JComponent. And FWIW since nothing said that JComponents are created with no children it is a very weak bug/complaint to begin with ! src/java.desktop/share/classes/javax/swing/JComponent.java line 185: > 183: * <p> > 184: * Containers inherited from <code>JComponent</code> can contain any > 185: * number of default components as children. This behaviour can also can we say "default or initial" src/java.desktop/share/classes/javax/swing/JComponent.java line 188: > 186: * change according to look and feel, as some look and feels may add a > 187: * default component to a container, where as other look and feels may > 188: * choose not to do so. "a" is not "any number" so you need to make your wording consistent. Also I think you need to say that even for a specific L&F it may vary depending on configuration properties of the JComponent. And perhaps finish with "In summary, it is not valid to assume a JComponent has no children just because the application did not directly add them" ? ------------- PR: https://git.openjdk.java.net/jdk/pull/5121