|
| 1 | +/* |
| 2 | + * Copyright (c) 2003, 2024, 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 4895367 |
| 27 | + * @summary List scrolling w/ down arrow keys obscures horizontal scrollbar |
| 28 | + * @library /java/awt/regtesthelpers |
| 29 | + * @build PassFailJFrame |
| 30 | + * @requires (os.family == "linux") |
| 31 | + * @run main/manual HorizScrollbarEraseTest |
| 32 | + */ |
| 33 | + |
| 34 | +import java.awt.BorderLayout; |
| 35 | +import java.awt.Button; |
| 36 | +import java.awt.Frame; |
| 37 | +import java.awt.GridLayout; |
| 38 | +import java.awt.List; |
| 39 | +import java.awt.Panel; |
| 40 | +import java.awt.TextArea; |
| 41 | +import java.awt.event.ActionEvent; |
| 42 | +import java.awt.event.ActionListener; |
| 43 | + |
| 44 | +public class HorizScrollbarEraseTest { |
| 45 | + |
| 46 | + private static final String INSTRUCTIONS = """ |
| 47 | + This is a Unix-only test. |
| 48 | + Do the four mini-tests below. |
| 49 | + If the horizontal scrollbar is ever erased by a rectangle |
| 50 | + of the background color, the test FAILS. |
| 51 | + If the horizontal scrollbars remain painted, test passes."""; |
| 52 | + |
| 53 | + public static void main(String[] args) throws Exception { |
| 54 | + PassFailJFrame.builder() |
| 55 | + .title("HorizScrollbarEraseTest Instructions") |
| 56 | + .instructions(INSTRUCTIONS) |
| 57 | + .rows((int) INSTRUCTIONS.lines().count() + 2) |
| 58 | + .columns(35) |
| 59 | + .testUI(HorizScrollbarEraseTest::createTestUI) |
| 60 | + .build() |
| 61 | + .awaitAndCheck(); |
| 62 | + } |
| 63 | + |
| 64 | + private static Frame createTestUI() { |
| 65 | + Frame frame = new Frame("HorizScrollbarEraseTest"); |
| 66 | + Panel borderPanel = new Panel(); |
| 67 | + borderPanel.setLayout(new BorderLayout()); |
| 68 | + Button focusedButton = new Button("Focus starts here"); |
| 69 | + borderPanel.add(focusedButton, BorderLayout.NORTH); |
| 70 | + |
| 71 | + Panel gridPanel = new Panel(); |
| 72 | + gridPanel.setLayout(new GridLayout(0, 4)); |
| 73 | + borderPanel.add(gridPanel, BorderLayout.CENTER); |
| 74 | + |
| 75 | + InstructionList il1 = new InstructionList("Tab to Item 2, then \n" + |
| 76 | + "press the down" + |
| 77 | + "arrow key to scroll down"); |
| 78 | + il1.list.select(2); |
| 79 | + il1.list.makeVisible(0); |
| 80 | + gridPanel.add(il1); |
| 81 | + |
| 82 | + InstructionList il2 = new InstructionList("Tab to the next List,\n" + |
| 83 | + "then press the down\n" + |
| 84 | + "arrow key to select\n" + |
| 85 | + "the last item."); |
| 86 | + il2.list.select(3); |
| 87 | + il2.list.makeVisible(0); |
| 88 | + gridPanel.add(il2); |
| 89 | + |
| 90 | + InstructionList il3 = new InstructionList("Click the button to\n" + |
| 91 | + "programmatically\n" + |
| 92 | + "select item 3 (not showing)"); |
| 93 | + Button selectBtn = new Button("Click Me"); |
| 94 | + final List selectList = il3.list; |
| 95 | + selectBtn.addActionListener(new ActionListener() { |
| 96 | + public void actionPerformed(ActionEvent e) { |
| 97 | + selectList.select(3); |
| 98 | + } |
| 99 | + }); |
| 100 | + il3.add(selectBtn, BorderLayout.CENTER); |
| 101 | + gridPanel.add(il3); |
| 102 | + |
| 103 | + InstructionList il4 = new InstructionList("Click the button to\nprogrammatically\ndeselect item 3\n(not showing)"); |
| 104 | + Button deselectBtn = new Button("Click Me"); |
| 105 | + final List deselectList = il4.list; |
| 106 | + deselectBtn.addActionListener(new ActionListener() { |
| 107 | + public void actionPerformed(ActionEvent e) { |
| 108 | + deselectList.deselect(3); |
| 109 | + } |
| 110 | + }); |
| 111 | + il4.add(deselectBtn, BorderLayout.CENTER); |
| 112 | + il4.list.select(3); |
| 113 | + il4.list.makeVisible(0); |
| 114 | + gridPanel.add(il4); |
| 115 | + |
| 116 | + frame.add(borderPanel); |
| 117 | + frame.pack(); |
| 118 | + return frame; |
| 119 | + |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +class InstructionList extends Panel { |
| 124 | + TextArea ta; |
| 125 | + public List list; |
| 126 | + |
| 127 | + public InstructionList(String instructions) { |
| 128 | + super(); |
| 129 | + setLayout(new BorderLayout()); |
| 130 | + ta = new TextArea(instructions, 6, 25, TextArea.SCROLLBARS_NONE); |
| 131 | + ta.setFocusable(false); |
| 132 | + list = new List(); |
| 133 | + for (int i = 0; i < 5; i++) { |
| 134 | + list.add("Item " + i + ", a long, long, long, long item"); |
| 135 | + } |
| 136 | + add(ta, BorderLayout.NORTH); |
| 137 | + add(list, BorderLayout.SOUTH); |
| 138 | + } |
| 139 | +} |
0 commit comments