< prev index next >

test/javax/swing/Popup/TaskbarPositionTest.java

Print this page

        

*** 60,77 **** private static char[] mnDayData = { 'M', 'T', 'W', 'R', 'F', 'S', 'U' }; public TaskbarPositionTest() { ! super("Use CTRL-down to show a JPopupMenu"); setContentPane(panel = createContentPane()); setJMenuBar(createMenuBar("1 - First Menu", true)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ! // CTRL-down will show the popup. panel.getInputMap().put(KeyStroke.getKeyStroke( ! KeyEvent.VK_DOWN, InputEvent.CTRL_MASK), "OPEN_POPUP"); panel.getActionMap().put("OPEN_POPUP", new PopupHandler()); pack(); Toolkit toolkit = Toolkit.getDefaultToolkit(); --- 60,77 ---- private static char[] mnDayData = { 'M', 'T', 'W', 'R', 'F', 'S', 'U' }; public TaskbarPositionTest() { ! super("Use down to show a JPopupMenu"); setContentPane(panel = createContentPane()); setJMenuBar(createMenuBar("1 - First Menu", true)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ! //Down will show the popup. panel.getInputMap().put(KeyStroke.getKeyStroke( ! KeyEvent.VK_DOWN, 0), "OPEN_POPUP"); panel.getActionMap().put("OPEN_POPUP", new PopupHandler()); pack(); Toolkit toolkit = Toolkit.getDefaultToolkit();
*** 110,125 **** --- 110,128 ---- JPopupMenu pm = (JPopupMenu) combo1.getUI().getAccessibleChild(combo1, 0); if (pm != null) { Point p = pm.getLocation(); SwingUtilities.convertPointToScreen(p, pm); + if (!UIManager.getLookAndFeel() + .getName().toLowerCase().contains("os x")) { if (p.y < cpos.y) { throw new RuntimeException("ComboBox popup is wrongly aligned"); } // check that popup was opened down } } } + } private class PopupHandler extends AbstractAction { public void actionPerformed(ActionEvent e) { if (!popupMenu.isVisible()) {
*** 184,197 **** item = popupMenu.add(new JMenuItem(dayData[i], mnDayData[i])); item.addActionListener(this); } panel.addMouseListener(new PopupListener(popupMenu)); ! JTextField field = new JTextField("CTRL+down for Popup"); ! // CTRL-down will show the popup. field.getInputMap().put(KeyStroke.getKeyStroke( ! KeyEvent.VK_DOWN, InputEvent.CTRL_MASK), "OPEN_POPUP"); field.getActionMap().put("OPEN_POPUP", new PopupHandler()); panel.add(field); return panel; --- 187,200 ---- item = popupMenu.add(new JMenuItem(dayData[i], mnDayData[i])); item.addActionListener(this); } panel.addMouseListener(new PopupListener(popupMenu)); ! JTextField field = new JTextField("Press down for Popup"); ! //Down will show the popup. field.getInputMap().put(KeyStroke.getKeyStroke( ! KeyEvent.VK_DOWN, 0), "OPEN_POPUP"); field.getActionMap().put("OPEN_POPUP", new PopupHandler()); panel.add(field); return panel;
*** 258,268 **** } } public static void main(String[] args) throws Throwable { - SwingUtilities.invokeAndWait(new Runnable() { public void run() { test = new TaskbarPositionTest(); } }); --- 261,270 ----
*** 294,319 **** Thread.sleep(500); robot.keyPress(KeyEvent.VK_DOWN); // How do we check combo boxes? - // Editable combo box robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); // combo1.getUI(); - // Popup from Text field robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); - robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); - robot.keyRelease(KeyEvent.VK_CONTROL); // Popup from a mouse click. Point pt = new Point(2, 2); SwingUtilities.convertPointToScreen(pt, panel); robot.mouseMove((int) pt.getX(), (int) pt.getY()); --- 296,317 ----
*** 334,340 **** --- 332,348 ---- robot.keyPress(KeyEvent.VK_ESCAPE); robot.keyRelease(KeyEvent.VK_ESCAPE); robot.waitForIdle(); Thread.sleep(500); + disposeGUI(); + } + + private static void disposeGUI() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + test.dispose(); + } + }); } } +
< prev index next >