Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8032872

[macosx] Cannot select from JComboBox in a JWindow

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b08
    • OS:
      os_x

      Backports

        Description



        Issue with Java version 7u17 / Mac only.

        Add a JComboBox to a JWindow. Show the window from a parent frame. The combo
        can be opened, but it does not allow selection from the mouse. The popup
        closes on mousePressed, but no selection is made. On other OSes and on Java
        1.6 the item is selected correctly on mouseReleased.

        Test case:
        import java.awt.FlowLayout;

        import java.awt.Point;
        import java.awt.Window;

        import java.awt.event.ActionEvent;

        import javax.swing.AbstractAction;
        import javax.swing.JButton;
        import javax.swing.JComboBox;
        import javax.swing.JFrame;
        import javax.swing.JLabel;
        import javax.swing.JPanel;
        import javax.swing.JWindow;
        import javax.swing.SwingUtilities;

        public class TestClass {
            public static void main(String[] args) {
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.setSize(300, 200);
                f.setLocationRelativeTo(null);

                f.setLayout(new FlowLayout());
                
                final JButton popButton = new JButton("Press me");
                popButton.addActionListener(new AbstractAction() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Window parentWin =
        SwingUtilities.windowForComponent(popButton);
                        JWindow popup = new JWindow(parentWin);
                        
                        JPanel panel = new JPanel(new FlowLayout());
                        panel.add(new JLabel("Cannot Select with Mouse:"));
                        panel.add(new JComboBox(new String[] { "One", "Two", "Three"
        }));
                        popup.add(panel);
                        Point p = popButton.getLocationOnScreen();
                        popup.add(panel);
                        popup.pack();
                        popup.setLocation(p.x, p.y + popButton.getHeight());
                        popup.setVisible(true);
                    }
                });

                f.add(popButton);
                f.setVisible(true);
            }
        }

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                dmarkov Dmitry Markov
                Reporter:
                asaha Abhijit Saha
                Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: