1 /* 2 * Copyright (c) 2016, 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 /** 25 * @test 26 * @bug 8158205 27 * @summary HiDPI hand cursor broken on Windows 28 * @run main/manual/othervm -Dsun.java2d.uiScale=2 MouseHandCursorTest 29 */ 30 import java.awt.Cursor; 31 import java.awt.GridBagLayout; 32 import java.awt.GridBagConstraints; 33 import java.awt.event.ActionEvent; 34 import java.awt.event.ActionListener; 35 import java.awt.event.WindowAdapter; 36 import java.awt.event.WindowEvent; 37 import java.util.concurrent.CountDownLatch; 38 import javax.swing.JFrame; 39 import javax.swing.JButton; 40 import javax.swing.JLabel; 41 import javax.swing.JPanel; 42 import javax.swing.SwingUtilities; 43 44 public class MouseHandCursorTest { 45 46 private static GridBagLayout layout; 47 private static JPanel mainControlPanel; 48 private static JPanel resultButtonPanel; 49 private static JLabel instructionText; 50 private static JButton passButton; 51 private static JButton failButton; 52 private static JFrame mainFrame; 53 private static CountDownLatch latch; 54 55 public static void main(String[] args) throws Exception { 56 latch = new CountDownLatch(1); 57 createUI(); 58 latch.await(); 59 } 60 61 public static void createUI() throws Exception { 62 SwingUtilities.invokeAndWait(new Runnable() { 63 @Override 64 public void run() { 65 mainFrame = new JFrame("Hand Cursor Test"); 66 layout = new GridBagLayout(); 67 mainControlPanel = new JPanel(layout); 68 resultButtonPanel = new JPanel(layout); 69 70 GridBagConstraints gbc = new GridBagConstraints(); 71 String instructions 72 = "<html><center>INSTRUCTIONS:</center><br>" 73 + "Check the mouse cursor type on frame.<br>" 74 + "If mouse cursor is hand cursor test passed else failed" 75 + "<br><br></html>"; 76 77 instructionText = new JLabel(); 78 instructionText.setText(instructions); 79 80 gbc.gridx = 0; 81 gbc.gridy = 0; 82 gbc.fill = GridBagConstraints.HORIZONTAL; 83 mainControlPanel.add(instructionText, gbc); 84 85 passButton = new JButton("Pass"); 86 passButton.setActionCommand("Pass"); 87 passButton.addActionListener((ActionEvent e) -> { 88 latch.countDown(); 89 mainFrame.dispose(); 90 }); 91 92 failButton = new JButton("Fail"); 93 failButton.setActionCommand("Fail"); 94 failButton.addActionListener(new ActionListener() { 95 @Override 96 public void actionPerformed(ActionEvent e) { 97 latch.countDown(); 98 mainFrame.dispose(); 99 throw new RuntimeException("Test Failed"); 100 } 101 }); 102 gbc.gridx = 2; 103 gbc.gridy = 0; 104 resultButtonPanel.add(passButton, gbc); 105 gbc.gridx = 3; 106 gbc.gridy = 0; 107 resultButtonPanel.add(failButton, gbc); 108 109 gbc.gridx = 0; 110 gbc.gridy = 2; 111 mainControlPanel.add(resultButtonPanel, gbc); 112 113 mainFrame.add(mainControlPanel); 114 mainFrame.setSize(400, 200); 115 mainFrame.setLocationRelativeTo(null); 116 mainFrame.setVisible(true); 117 118 mainFrame.addWindowListener(new WindowAdapter() { 119 @Override 120 public void windowClosing(WindowEvent e) { 121 latch.countDown(); 122 mainFrame.dispose(); 123 } 124 }); 125 mainFrame.getContentPane().setCursor(Cursor. 126 getPredefinedCursor(Cursor.HAND_CURSOR)); 127 } 128 }); 129 } 130 }