Re: setActionListener problems

Frank Langelage <[email protected]>
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
Today I found a logical error in method SwingEngine.setActionListener.

The result was, that the menuItems didn't get the the actionListener, 
only the Buttons got it.
The reason for this is the following code:

if (!b) {
    if (AbstractButton.class.isAssignableFrom( c.getClass() )) {
        ( (AbstractButton) c ).addActionListener( al );
        b = true;
    } else if (JMenu.class.isAssignableFrom( c.getClass() )) {
        final JMenu m = (JMenu) c;
        final int k = m.getItemCount();
        for (int i = 0; i < k; i++) {
            b = b | setActionListener( m.getItem( i ), al );
        }
    }
}

A JMenu is also a SubClass of AbstractButton, so the "else if 
(JMenu...." is never reached.
I've changed the order of the code blocks above to get it working:

if (!b) {
    if (JMenu.class.isAssignableFrom( c.getClass() )) {
        final JMenu m = (JMenu) c;
        final int k = m.getItemCount();
        for (int i = 0; i < k; i++) {
            b = b | setActionListener( m.getItem( i ), al );
        }
    } else if (AbstractButton.class.isAssignableFrom( c.getClass() )) {
        ( (AbstractButton) c ).addActionListener( al );
        b = true;
    }
}

I'll hope to see this bug fix in the next version SwiXml 1.0.2.

Regards
Frank
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.