|
| 1 | +/* |
| 2 | + * Copyright (c) 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 8268145 |
| 27 | + * @library /java/awt/regtesthelpers |
| 28 | + * @build PassFailJFrame |
| 29 | + * @requires (os.family == "mac") |
| 30 | + * @summary Verify rendering artifact is not seen moving caret inside |
| 31 | + * JTable with TableCellEditor having JTextField |
| 32 | + * @run main/manual TestCaretArtifact |
| 33 | + */ |
| 34 | + |
| 35 | +import javax.swing.DefaultCellEditor; |
| 36 | +import javax.swing.JFrame; |
| 37 | +import javax.swing.JTable; |
| 38 | +import javax.swing.JTextField; |
| 39 | +import javax.swing.table.TableCellEditor; |
| 40 | +import javax.swing.table.TableColumn; |
| 41 | +import javax.swing.SwingUtilities; |
| 42 | + |
| 43 | +public class TestCaretArtifact { |
| 44 | + |
| 45 | + private static final String INSTRUCTIONS = """ |
| 46 | + Double click on "Click Here" textfield so that textfield becomes editable; |
| 47 | + Press spacebar. Press left arrow button. |
| 48 | + Do this few times. |
| 49 | + If artifact is seen, press Fail else press Pass."""; |
| 50 | + |
| 51 | + public static void main(String[] args) throws Exception { |
| 52 | + PassFailJFrame.builder() |
| 53 | + .title("Caret Artifact Instructions") |
| 54 | + .instructions(INSTRUCTIONS) |
| 55 | + .columns(35) |
| 56 | + .testUI(TestCaretArtifact::createUI) |
| 57 | + .build() |
| 58 | + .awaitAndCheck(); |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + public static JFrame createUI() { |
| 63 | + TableCellEditor editor = new TestEditor(new JTextField()); |
| 64 | + JTable table = new JTable(new Object[][] {{"click here", |
| 65 | + "inactive forever"}}, |
| 66 | + new Object[] {"1", "2"}); |
| 67 | + |
| 68 | + JFrame frame = new JFrame("CaretArtifact"); |
| 69 | + TableColumn column = table.getColumn("1"); |
| 70 | + column.setCellEditor(editor); |
| 71 | + frame.getContentPane().add("Center", table); |
| 72 | + frame.setSize(400, 100); |
| 73 | + |
| 74 | + return frame; |
| 75 | + } |
| 76 | + |
| 77 | + static class TestEditor extends DefaultCellEditor { |
| 78 | + public TestEditor(JTextField tf) { |
| 79 | + super(tf); |
| 80 | + } |
| 81 | + public boolean stopCellEditing() { |
| 82 | + return false; |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
0 commit comments