jdk/test/javax/swing/JComboBox/8041909/ActionListenerExceptionTest.java
changeset 42738 67c248b945d5
parent 39521 c169f36c9a4b
child 46151 5fa789776f7d
equal deleted inserted replaced
42737:b37da02bd6c1 42738:67c248b945d5
    24  /* @test
    24  /* @test
    25   * @bug 8041909
    25   * @bug 8041909
    26   * @summary Test to check JComboBox does not lose its ability to invoke
    26   * @summary Test to check JComboBox does not lose its ability to invoke
    27   * registerd ActionListener in case of exception in ActionListener
    27   * registerd ActionListener in case of exception in ActionListener
    28   * @run main ActionListenerExceptionTest
    28   * @run main ActionListenerExceptionTest
    29   */
    29  */
    30 
    30 
    31 import java.awt.AWTEvent;
    31 import java.awt.AWTEvent;
    32 import java.awt.AWTException;
    32 import java.awt.AWTException;
    33 import java.awt.Dimension;
    33 import java.awt.Dimension;
    34 import java.awt.EventQueue;
    34 import java.awt.EventQueue;
    42 import java.util.logging.Logger;
    42 import java.util.logging.Logger;
    43 import javax.swing.JComboBox;
    43 import javax.swing.JComboBox;
    44 import javax.swing.JComponent;
    44 import javax.swing.JComponent;
    45 import javax.swing.JFrame;
    45 import javax.swing.JFrame;
    46 import javax.swing.JPopupMenu;
    46 import javax.swing.JPopupMenu;
       
    47 import javax.swing.JScrollPane;
    47 import javax.swing.SwingUtilities;
    48 import javax.swing.SwingUtilities;
    48 
    49 
    49 public class ActionListenerExceptionTest {
    50 public class ActionListenerExceptionTest {
    50 
    51 
    51     static final int TOTAL_MENU_ITEMS = 3;
    52     static final int TOTAL_MENU_ITEMS = 3;
   131         testRobot.delay(500); // delay to make popup visible
   132         testRobot.delay(500); // delay to make popup visible
   132 
   133 
   133         SwingUtilities.invokeAndWait(new Runnable() {
   134         SwingUtilities.invokeAndWait(new Runnable() {
   134             public void run() {
   135             public void run() {
   135                 Object comp = combo.getUI().getAccessibleChild(combo, 0);
   136                 Object comp = combo.getUI().getAccessibleChild(combo, 0);
   136                 JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
   137                 int i = 0;
       
   138                 JComponent scrollPane;
       
   139                 do {
       
   140                     scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(i++);
       
   141                 } while (!(scrollPane instanceof JScrollPane));
   137 
   142 
   138                 menuItemHeight = scrollPane.getSize().height / TOTAL_MENU_ITEMS;
   143                 menuItemHeight = scrollPane.getSize().height / TOTAL_MENU_ITEMS;
   139                 yPos = scrollPane.getLocationOnScreen().y + menuItemHeight / 2;
   144                 yPos = scrollPane.getLocationOnScreen().y + menuItemHeight / 2;
   140             }
   145             }
   141         });
   146         });