1 /* 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 @bug 7158712 26 @summary Synth Property "ComboBox.popupInsets" is ignored 27 @library ../../../regtesthelpers 28 @author Pavel Porvatov 29 */ 30 31 import sun.awt.SunToolkit; 32 33 import javax.swing.*; 34 import javax.swing.plaf.basic.BasicComboPopup; 35 import javax.swing.plaf.synth.SynthLookAndFeel; 36 import java.awt.*; 37 import java.awt.event.InputEvent; 38 import java.io.ByteArrayInputStream; 39 import java.util.concurrent.Callable; 40 41 public class bug7158712 { 42 private static final String SYNTH_XML = "<synth>" + 43 " <style id=\"all\">" + 44 " <font name=\"Dialog\" size=\"12\"/>" + 45 " </style>" + 46 " <bind style=\"all\" type=\"REGION\" key=\".*\"/>" + 47 " <style id=\"arrowButton\">" + 48 " <property key=\"ArrowButton.size\" type=\"integer\" value=\"18\"/>" + 49 " </style>" + 50 " <bind style=\"arrowButton\" type=\"region\" key=\"ArrowButton\"/>" + 51 " <style id=\"comboBox\">" + 52 " <property key=\"ComboBox.popupInsets\" type=\"insets\" value=\"-5 -5 5 -5\"/>" + 53 " </style>" + 54 " <bind style=\"comboBox\" type=\"region\" key=\"ComboBox\"/>" + 55 "</synth>"; 56 57 private static JComboBox<String> comboBox; 58 59 public static void main(String[] args) throws Exception { 60 Robot robot = new Robot(); 61 62 robot.setAutoDelay(500); 63 64 SynthLookAndFeel laf = new SynthLookAndFeel(); 65 66 laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class); 67 68 UIManager.setLookAndFeel(laf); 69 70 EventQueue.invokeAndWait(new Runnable() { 71 public void run() { 72 comboBox = new JComboBox<>( 73 new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"}); 74 75 JFrame frame = new JFrame(); 76 77 frame.add(comboBox, BorderLayout.NORTH); 78 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 79 frame.setSize(new Dimension(400, 300)); 80 frame.setLocationRelativeTo(null); 81 frame.setVisible(true); 82 } 83 }); 84 85 ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); 86 87 Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() { 88 @Override 89 public Point call() throws Exception { 90 return comboBox.getLocationOnScreen(); 91 } 92 }); 93 94 robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y); 95 robot.mousePress(InputEvent.BUTTON1_MASK); 96 robot.mouseRelease(InputEvent.BUTTON1_MASK); 97 98 SwingUtilities.invokeAndWait(new Runnable() { 99 @Override 100 public void run() { 101 BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0); 102 103 Point popupPoint = popup.getLocationOnScreen(); 104 Point comboBoxPoint = comboBox.getLocationOnScreen(); 105 106 if (comboBoxPoint.x - 5 != popupPoint.x || 107 comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) { 108 throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint + 109 ", comboBox location: " + comboBoxPoint); 110 } 111 112 System.out.println("Test bug7158712 passed"); 113 } 114 }); 115 } 116 }