<Swing Dev> RFR: 8272148: JDesktopPane:getComponentCount() returns one extra than expected with GTKLookAndFeel

Pankaj Bansal pbansal at openjdk.java.net
Fri Aug 20 05:44:27 UTC 2021


On Thu, 19 Aug 2021 22:41:04 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

> 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.

`

        public static void main(String[] args) throws Exception{
        for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            JComboBox<String> container = new JComboBox();
            System.out.println("**************");
            UIManager.setLookAndFeel(info.getClassName());
            System.out.println("Current Look and Feel is "+info.getName());
            if (container.getComponentCount() == 0) {
                System.out.println("Expected : no child components present");
            } else {
                System.out.println("Unexpected : by default the Container has components size " + container.getComponentCount());
                System.out.println("Following are the components present");
                for (Component c : container.getComponents())
                    System.out.println(c);
            }
            System.out.println("**************");
            System.out.println();
        }
    }
   
`

`

**************
Current Look and Feel is Metal
Unexpected : by default the Container has components size 2
Following are the components present
com.apple.laf.AquaComboBoxButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,border=com.apple.laf.AquaButtonBorder$Named at 3bfdc050,flags=12583200,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=0,left=2,bottom=0,right=2],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=,defaultCapable=true]
javax.swing.CellRendererPane[,0,0,0x0,invalid,hidden]
**************

**************
Current Look and Feel is Nimbus
Unexpected : by default the Container has components size 2
Following are the components present
javax.swing.plaf.metal.MetalComboBoxButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource at 5bb21b69,flags=12583208,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=java.awt.Insets[top=0,left=1,bottom=1,right=3],paintBorder=true,paintFocus=false,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=,defaultCapable=true]
javax.swing.CellRendererPane[,0,0,0x0,invalid,hidden]
**************

**************
Current Look and Feel is CDE/Motif
Unexpected : by default the Container has components size 2
Following are the components present
javax.swing.plaf.synth.SynthArrowButton[ComboBox.arrowButton,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.synth.SynthBorder at 4690b489,flags=12583200,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=,defaultCapable=false]
javax.swing.CellRendererPane[,0,0,0x0,invalid,hidden]
**************

**************
Current Look and Feel is Mac OS X
Unexpected : by default the Container has components size 1
Following are the components present
javax.swing.CellRendererPane[,0,0,0x0,invalid,hidden]
**************

`

-------------

PR: https://git.openjdk.java.net/jdk/pull/5121


More information about the swing-dev mailing list