|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2025, 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 4119993 |
| 26 | + * @library /java/awt/regtesthelpers |
| 27 | + * @build PassFailJFrame |
| 28 | + * @summary Check that mouse button 3 is reserved for popup invocation not selection. |
| 29 | + * @run main/manual bug4119993 |
| 30 | + */ |
| 31 | + |
| 32 | +import java.awt.BorderLayout; |
| 33 | +import java.awt.Dimension; |
| 34 | +import javax.swing.BoxLayout; |
| 35 | +import javax.swing.JFrame; |
| 36 | +import javax.swing.JLabel; |
| 37 | +import javax.swing.JList; |
| 38 | +import javax.swing.JPanel; |
| 39 | +import javax.swing.JScrollPane; |
| 40 | +import javax.swing.JTable; |
| 41 | +import javax.swing.JTextArea; |
| 42 | +import javax.swing.border.BevelBorder; |
| 43 | + |
| 44 | +/* |
| 45 | + * This is a sort of negative test. Mouse Button 3 is not supposed to cause selections. |
| 46 | + * If it did, then it would not be useable to invoke popup menus. |
| 47 | + * So this popup menu test .. does not popup menus. |
| 48 | + */ |
| 49 | + |
| 50 | +public class bug4119993 { |
| 51 | + |
| 52 | + static final String INSTRUCTIONS = """ |
| 53 | +<html> |
| 54 | + The test window contains a text area, a table, and a list. |
| 55 | + <p> |
| 56 | + For each component, try to select text/cells/rows/items as appropriate |
| 57 | + using the <font size=+2 color=red>RIGHT</font> mouse button (Mouse Button 3). |
| 58 | + <p> |
| 59 | + If the selection changes, then press <em><b>FAIL</b></em>. |
| 60 | + <p> |
| 61 | + If the selection does not change, press <em><b>PASS</b></em></html |
| 62 | + </html> |
| 63 | + """; |
| 64 | + |
| 65 | + public static void main(String[] args) throws Exception { |
| 66 | + PassFailJFrame.builder() |
| 67 | + .instructions(INSTRUCTIONS) |
| 68 | + .columns(60) |
| 69 | + .testUI(bug4119993::createUI) |
| 70 | + .build() |
| 71 | + .awaitAndCheck(); |
| 72 | + } |
| 73 | + |
| 74 | + static JFrame createUI() { |
| 75 | + JFrame frame = new JFrame("bug4119993"); |
| 76 | + JPanel p = new JPanel(); |
| 77 | + p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
| 78 | + frame.add(p); |
| 79 | + |
| 80 | + String text = "This is some text that you should try to select using the right mouse button"; |
| 81 | + JTextArea area = new JTextArea(text, 5, 40); |
| 82 | + JScrollPane scrollpane0 = new JScrollPane(area); |
| 83 | + scrollpane0.setBorder(new BevelBorder(BevelBorder.LOWERED)); |
| 84 | + scrollpane0.setPreferredSize(new Dimension(430, 200)); |
| 85 | + p.add(scrollpane0); |
| 86 | + |
| 87 | + String[][] data = new String[5][5]; |
| 88 | + String[] cols = new String[5]; |
| 89 | + for (int r = 0; r < 5; r ++) { |
| 90 | + cols[r] = "col " + r; |
| 91 | + for (int c = 0; c < 5; c ++) { |
| 92 | + data[r][c] = "(" + r + "," + c + ")"; |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + JTable tableView = new JTable(data, cols); |
| 97 | + JScrollPane scrollpane = new JScrollPane(tableView); |
| 98 | + scrollpane.setBorder(new BevelBorder(BevelBorder.LOWERED)); |
| 99 | + scrollpane.setPreferredSize(new Dimension(430, 200)); |
| 100 | + p.add(scrollpane); |
| 101 | + |
| 102 | + String[] s = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; |
| 103 | + JList listView = new JList(s); |
| 104 | + JScrollPane scrollpane2 = new JScrollPane(listView); |
| 105 | + scrollpane2.setBorder(new BevelBorder(BevelBorder.LOWERED)); |
| 106 | + scrollpane2.setPreferredSize(new Dimension(430, 200)); |
| 107 | + p.add(scrollpane2); |
| 108 | + |
| 109 | + frame.pack(); |
| 110 | + return frame; |
| 111 | + } |
| 112 | +} |
0 commit comments