bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/23029] Swing: JMenu - setSelected behavior


From: gcc-bugzilla at gcc dot gnu dot org
Subject: [Bug classpath/23029] Swing: JMenu - setSelected behavior
Date: 8 Sep 2010 18:04:53 -0000

Call JMenu.setSelected(true):

JDK:

- JMenu will appear as selected (highlighted background) regardless of whether
the menu is enabled or not. (Popup window will *not* show up)

Classpath 0.16:

- JMenu will appear selected and the popup is opened only when the menu is
enabled
- nothing happens when the menu is disabled.

Test code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test {

        public static void main(String[] args) throws Exception {
                final JFrame f = new JFrame("License choser");

                Container cp = f.getContentPane();
                cp.setLayout(new FlowLayout());

                final JMenuBar bar = new JMenuBar();
                final JCheckBox switcher = new JCheckBox("enable menu", true);
                final JButton selecter = new JButton("select GNU");

                cp.add(switcher);
                cp.add(selecter);

                final JMenu gnu = new JMenu("GNU");
                gnu.setMnemonic(KeyEvent.VK_G);

                gnu.add(new JMenuItem("GPL"));
                gnu.add(new JMenuItem("LGPL"));
                gnu.add(new JMenuItem("GFDL"));

                final JMenu asf = new JMenu("ASF");
                asf.setMnemonic(KeyEvent.VK_A);

                asf.add(new JMenuItem("ASL 2.0"));
                asf.add(new JMenuItem("ASL 1.0"));

                final JMenu bsd = new JMenu("BSD");
                bsd.setMnemonic(KeyEvent.VK_B);

                bsd.add(new JMenuItem("mod. BSDL"));
                bsd.add(new JMenuItem("MIT X11"));

                bar.add(asf);
                bar.add(bsd);
                bar.add(gnu);

                f.setJMenuBar(bar);

                switcher.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent ae) {
                                boolean t = switcher.isSelected();
                                gnu.setEnabled(t);
                                asf.setEnabled(t);
                                bsd.setEnabled(t);
                                System.out.println("JMenu is set to " + (t ?
"on" : "off"));
                        }
                });

                selecter.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent ae) {
                                gnu.setSelected(true);
                        }
                });

                f.pack();

                f.show();

                f.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent we) {
                                f.dispose();
                                System.exit(0);
                        }
                });

        }

}

You will see 3 menus in the bar.

With enabled menus (checked checkbox) click on "select GNU". On JDK this will
hightlight the GNU menu. On Classpath it will highlight the menu AND open the
popup window.

With an unchecked checkbox, click "select GNU". On JDK this will highlight the
"GNU" menu - on Classpath nothing happens.


------- Comment #1 from from-classpath at savannah dot gnu dot org  2005-07-08 
10:22 -------
The menu opening when its set to disabled, is already fixed in cvs.
I have discovered another bug in this testcase. If you open a menu, you can see
in the taskbar that a new window with the name "." has been opened.
And also, on the sun vm if you click on the checkbox you have this output in
the console:
JMenu is set to off

but with classpath you get:
JMenu is set to on

Perhaps classpath first triggers a actionPerformed ActionEvent and only
afterwards changes the selection of the checkbox?


------- Comment #2 from from-classpath at savannah dot gnu dot org  2005-07-09 
00:14 -------
> Perhaps classpath first triggers a actionPerformed ActionEvent 
> and only afterwards changes the selection of the checkbox?
Indeed. I think something is wrong with our JCheckBox.


------- Comment #3 from from-classpath at savannah dot gnu dot org  2005-07-12 
20:52 -------
Great!

The behavior of the JDK is matched perfectly.

Thanks for fixing this.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23029




reply via email to

[Prev in Thread] Current Thread [Next in Thread]