From 456559564c911eca36936496910c24b6a6aab391 Mon Sep 17 00:00:00 2001 From: Alisen Chung Date: Thu, 17 Apr 2025 10:59:59 -0700 Subject: [PATCH 1/5] opening tests --- .../swing/JTable/InternationalCharacters.java | 178 +++++++++++++++++ .../javax/swing/JTable/NullTableHeader.java | 46 +++++ test/jdk/javax/swing/JTable/bug4118307.java | 184 ++++++++++++++++++ test/jdk/javax/swing/JTable/bug4138158.java | 62 ++++++ 4 files changed, 470 insertions(+) create mode 100644 test/jdk/javax/swing/JTable/InternationalCharacters.java create mode 100644 test/jdk/javax/swing/JTable/NullTableHeader.java create mode 100644 test/jdk/javax/swing/JTable/bug4118307.java create mode 100644 test/jdk/javax/swing/JTable/bug4138158.java diff --git a/test/jdk/javax/swing/JTable/InternationalCharacters.java b/test/jdk/javax/swing/JTable/InternationalCharacters.java new file mode 100644 index 0000000000000..e1ebb50b69eac --- /dev/null +++ b/test/jdk/javax/swing/JTable/InternationalCharacters.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import javax.swing.DefaultCellEditor; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.border.BevelBorder; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; + +/* + * @test + * @bug 4179066 + * @summary Tests that JTable prints AltGr characters (~\@|{}[]²µ³) + * @library /open/test/jdk/java/awt/regtesthelpers + * @build PassFailJFrame + * @run main InternationalCharacters + */ + +public class InternationalCharacters { + private static final String INSTRUCTIONS = """ + Double-click an entry in the JTable. + Press Alt-Gr or Option with any key to type an international character. + Verify that the international character appears in the table. + If it does, press "pass", otherwise press "fail". + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .instructions(INSTRUCTIONS) + .columns(50) + .testUI(InternationalCharacters::createTestUI) + .build() + .awaitAndCheck(); + } + + public static JFrame createTestUI() { + JFrame frame = new JFrame("InternationalCharacters test"); + // Take the dummy data from SwingSet. + final String[] names = {"First Name", "Last Name", "Favorite Color", + "Favorite Number", "Vegetarian"}; + final Object[][] data = { + {"Mark", "Andrews", "Red", 2, true}, + {"Tom", "Ball", "Blue", 99, false}, + {"Alan", "Chung", "Green", 838, false}, + {"Jeff", "Dinkins", "Turquois", 8, true}, + {"Amy", "Fowler", "Yellow", 3, false}, + {"Brian", "Gerhold", "Green", 0, false}, + {"James", "Gosling", "Pink", 21, false}, + {"David", "Karlton", "Red", 1, false}, + {"Dave", "Kloba", "Yellow", 14, false}, + {"Peter", "Korn", "Purple", 12, false}, + {"Phil", "Milne", "Purple", 3, false}, + {"Dave", "Moore", "Green", 88, false}, + {"Hans", "Muller", "Maroon", 5, false}, + {"Rick", "Levenson", "Blue", 2, false}, + {"Tim", "Prinzing", "Blue", 22, false}, + {"Chester", "Rose", "Black", 0, false}, + {"Ray", "Ryan", "Gray", 77, false}, + {"Georges", "Saab", "Red", 4, false}, + {"Willie", "Walker", "Phthalo Blue", 4, false}, + {"Kathy", "Walrath", "Blue", 8, false}, + {"Arnaud", "Weber", "Green", 44, false} + }; + + // Create a model of the data. + TableModel dataModel = new AbstractTableModel() { + // These methods always need to be implemented. + public int getColumnCount() { return names.length; } + public int getRowCount() { return data.length;} + public Object getValueAt(int row, int col) {return data[row][col];} + + // The default implementations of these methods in + // AbstractTableModel would work, but we can refine them. + public String getColumnName(int column) {return names[column];} + public Class getColumnClass(int c) {return getValueAt(0, c).getClass();} + public boolean isCellEditable(int row, int col) {return true;} + public void setValueAt(Object aValue, int row, int column) { + System.out.println("Setting value to: " + aValue); + data[row][column] = aValue; + } + }; + + // Create the table + JTable tableView = new JTable(dataModel); + // Turn off auto-resizing so that we can set column sizes programmatically. + // In this mode, all columns will get their preferred widths, as set blow. + tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + + // Create a combo box to show that you can use one in a table. + JComboBox comboBox = new JComboBox(); + comboBox.addItem("Red"); + comboBox.addItem("Orange"); + comboBox.addItem("Yellow"); + comboBox.addItem("Green"); + comboBox.addItem("Blue"); + comboBox.addItem("Indigo"); + comboBox.addItem("Violet"); + + TableColumn colorColumn = tableView.getColumn("Favorite Color"); + // Use the combo box as the editor in the "Favorite Color" column. + colorColumn.setCellEditor(new DefaultCellEditor(comboBox)); + + // Set a pink background and tooltip for the Color column renderer. + DefaultTableCellRenderer colorColumnRenderer = new DefaultTableCellRenderer(); + colorColumnRenderer.setBackground(Color.pink); + colorColumnRenderer.setToolTipText("Click for combo box"); + colorColumn.setCellRenderer(colorColumnRenderer); + + // Set a tooltip for the header of the colors column. + TableCellRenderer headerRenderer = colorColumn.getHeaderRenderer(); + if (headerRenderer instanceof DefaultTableCellRenderer) + ((DefaultTableCellRenderer)headerRenderer).setToolTipText("Hi Mom!"); + + // Set the width of the "Vegetarian" column. + TableColumn vegetarianColumn = tableView.getColumn("Vegetarian"); + vegetarianColumn.setPreferredWidth(100); + + // Show the values in the "Favorite Number" column in different colors. + TableColumn numbersColumn = tableView.getColumn("Favorite Number"); + DefaultTableCellRenderer numberColumnRenderer = new DefaultTableCellRenderer() { + public void setValue(Object value) { + int cellValue = (value instanceof Number) ? ((Number)value).intValue() : 0; + setForeground((cellValue > 30) ? Color.black : Color.red); + setText((value == null) ? "" : value.toString()); + } + }; + numberColumnRenderer.setHorizontalAlignment(JLabel.RIGHT); + numbersColumn.setCellRenderer(numberColumnRenderer); + numbersColumn.setPreferredWidth(110); + + // Finish setting up the table. + JScrollPane scrollpane = new JScrollPane(tableView); + scrollpane.setBorder(new BevelBorder(BevelBorder.LOWERED)); + scrollpane.setPreferredSize(new Dimension(430, 200)); + + WindowListener l = new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }; + frame.addWindowListener(l); + frame.add(scrollpane); + frame.setSize(500, 200); + return frame; + } +} diff --git a/test/jdk/javax/swing/JTable/NullTableHeader.java b/test/jdk/javax/swing/JTable/NullTableHeader.java new file mode 100644 index 0000000000000..dd6b3a3afe1f7 --- /dev/null +++ b/test/jdk/javax/swing/JTable/NullTableHeader.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.JFrame; +import javax.swing.JTable; +import javax.swing.SwingUtilities; + +/* + * @test + * @bug 4129409 + * @summary Tests that JTable.setTableHeader(null) doesn't break AutoResize + * @key headful + * @run main NullTableHeader + */ + +public class NullTableHeader { + static JTable tableView; + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(() -> { + tableView = new JTable(); + tableView.setTableHeader(null); + tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + }); + } +} diff --git a/test/jdk/javax/swing/JTable/bug4118307.java b/test/jdk/javax/swing/JTable/bug4118307.java new file mode 100644 index 0000000000000..d878be80b14c2 --- /dev/null +++ b/test/jdk/javax/swing/JTable/bug4118307.java @@ -0,0 +1,184 @@ +/* + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.SwingUtilities; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableModel; + +/* + * @test + * @bug 4118307 + * @summary Tests that JTable's cell editor for Number and Date work correctly + * @key headful + * @run main bug4118307 + */ + +public class bug4118307 { + static JFrame frame; + static MyTable tbl; + static Point tableLoc; + static Point p; + private static boolean flag = false; + static final String[] columnNames = {"Integer", "Double"}; + static final Object[][] data = { + {5, 3.14}, + {10, 2.71}, + {70, 3.14}, + {200, 2.71}, + }; + + public static void main(String[] args) throws Exception { + try { + Robot robot = new Robot(); + robot.setAutoDelay(250); + SwingUtilities.invokeAndWait(() -> createTestUI()); + robot.waitForIdle(); + + SwingUtilities.invokeAndWait(() -> { + tableLoc = tbl.getLocationOnScreen(); + p = tbl.getCellRect(0, 0, true).getLocation(); + }); + robot.waitForIdle(); + + robot.mouseMove(tableLoc.x + p.x + 10, tableLoc.y + p.y + 10); + robot.waitForIdle(); + + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + + SwingUtilities.invokeAndWait(() -> + p = tbl.getCellRect(1, 1, true).getLocation()); + robot.waitForIdle(); + + robot.mouseMove(tableLoc.x + p.x + 10, tableLoc.y + p.y + 10); + robot.waitForIdle(); + + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + + SwingUtilities.invokeAndWait(() -> + p = tbl.getCellRect(1, 0, true).getLocation()); + robot.waitForIdle(); + + robot.mouseMove(tableLoc.x + p.x + 10, tableLoc.y + p.y + 10); + robot.waitForIdle(); + + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + robot.delay(5000); + + if (isFail()) { + throw new RuntimeException("Test Failed."); + } + } finally { + SwingUtilities.invokeAndWait(() -> { + if (frame != null) { + frame.dispose(); + } + }); + } + } + + public static void createTestUI() { + frame = new JFrame("bug4118307"); + MyTableModel myModel = new MyTableModel(); + tbl = new MyTable(myModel); + JScrollPane sp = new JScrollPane(tbl); + frame.add(sp, BorderLayout.CENTER); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + static synchronized void setFail() { + flag = true; + } + + static synchronized boolean isFail() { + return flag; + } + + static class MyTable extends JTable { + public MyTable(TableModel tm) { + super(tm); + } + + public Component prepareRenderer(TableCellRenderer rend, int row, int col) { + try { + return super.prepareRenderer(rend, row, col); + } catch (Exception e) { + e.printStackTrace(); + setFail(); + return null; + } + } + } + + static class MyTableModel extends AbstractTableModel { + public int getColumnCount() { + return columnNames.length; + } + + public int getRowCount() { + return data.length; + } + + public String getColumnName(int col) { + return columnNames[col]; + } + + public Object getValueAt(int row, int col) { + return data[row][col]; + } + + public Class getColumnClass(int c) { + return getValueAt(0, c).getClass(); + } + + public boolean isCellEditable(int row, int col) { + return true; + } + + public void setValueAt(Object value, int row, int col) { + data[row][col] = value; + } + } +} diff --git a/test/jdk/javax/swing/JTable/bug4138158.java b/test/jdk/javax/swing/JTable/bug4138158.java new file mode 100644 index 0000000000000..09451b800c97f --- /dev/null +++ b/test/jdk/javax/swing/JTable/bug4138158.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTable; + +/* + * @test + * @bug 4138158 + * @summary Tests that setAutoscrolls(false) locks autoscroll + * @library /open/test/jdk/java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual bug4138158 + */ + +public class bug4138158 { + private static final String INSTRUCTIONS = """ + Move mouse to beginning of table, press left mouse button and move mouse down + so that mouse cursor is below the bottom border of table. If the table isn't + scrolled down then test passes. If the table is scrolled then test fails. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .instructions(INSTRUCTIONS) + .columns(50) + .testUI(bug4138158::createTestUI) + .build() + .awaitAndCheck(); + } + + public static JFrame createTestUI() { + JFrame frame = new JFrame("bug4138158"); + JTable table = new JTable(20, 3); + table.setAutoscrolls(false); + JScrollPane sp = new JScrollPane(table); + frame.add(sp); + frame.pack(); + return frame; + } +} From 9bfe14931d8958df6b034bc126bd72cf08293d0e Mon Sep 17 00:00:00 2001 From: Alisen Chung Date: Thu, 17 Apr 2025 11:36:24 -0700 Subject: [PATCH 2/5] update jtreg paths --- test/jdk/javax/swing/JTable/InternationalCharacters.java | 2 +- test/jdk/javax/swing/JTable/bug4138158.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/jdk/javax/swing/JTable/InternationalCharacters.java b/test/jdk/javax/swing/JTable/InternationalCharacters.java index e1ebb50b69eac..34150a87163fa 100644 --- a/test/jdk/javax/swing/JTable/InternationalCharacters.java +++ b/test/jdk/javax/swing/JTable/InternationalCharacters.java @@ -43,7 +43,7 @@ * @test * @bug 4179066 * @summary Tests that JTable prints AltGr characters (~\@|{}[]²µ³) - * @library /open/test/jdk/java/awt/regtesthelpers + * @library /java/awt/regtesthelpers * @build PassFailJFrame * @run main InternationalCharacters */ diff --git a/test/jdk/javax/swing/JTable/bug4138158.java b/test/jdk/javax/swing/JTable/bug4138158.java index 09451b800c97f..f728ec0a923a4 100644 --- a/test/jdk/javax/swing/JTable/bug4138158.java +++ b/test/jdk/javax/swing/JTable/bug4138158.java @@ -29,7 +29,7 @@ * @test * @bug 4138158 * @summary Tests that setAutoscrolls(false) locks autoscroll - * @library /open/test/jdk/java/awt/regtesthelpers + * @library /java/awt/regtesthelpers * @build PassFailJFrame * @run main/manual bug4138158 */ From b514a695af68e7e70ee4836ad88a5f6d2a717f40 Mon Sep 17 00:00:00 2001 From: Alisen Chung Date: Fri, 18 Apr 2025 15:41:48 -0700 Subject: [PATCH 3/5] manual jtreg tag, make jtable field local --- test/jdk/javax/swing/JTable/InternationalCharacters.java | 2 +- test/jdk/javax/swing/JTable/NullTableHeader.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/jdk/javax/swing/JTable/InternationalCharacters.java b/test/jdk/javax/swing/JTable/InternationalCharacters.java index 34150a87163fa..f9665a22b7295 100644 --- a/test/jdk/javax/swing/JTable/InternationalCharacters.java +++ b/test/jdk/javax/swing/JTable/InternationalCharacters.java @@ -45,7 +45,7 @@ * @summary Tests that JTable prints AltGr characters (~\@|{}[]²µ³) * @library /java/awt/regtesthelpers * @build PassFailJFrame - * @run main InternationalCharacters + * @run main/manual InternationalCharacters */ public class InternationalCharacters { diff --git a/test/jdk/javax/swing/JTable/NullTableHeader.java b/test/jdk/javax/swing/JTable/NullTableHeader.java index dd6b3a3afe1f7..dc62b975d045d 100644 --- a/test/jdk/javax/swing/JTable/NullTableHeader.java +++ b/test/jdk/javax/swing/JTable/NullTableHeader.java @@ -34,11 +34,9 @@ */ public class NullTableHeader { - static JTable tableView; - public static void main(String[] args) throws Exception { SwingUtilities.invokeAndWait(() -> { - tableView = new JTable(); + JTable tableView = new JTable(); tableView.setTableHeader(null); tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); }); From 2ea9db42e47ed3f3d3b0cddc9af2b11cbb69b5a4 Mon Sep 17 00:00:00 2001 From: Alisen Chung Date: Mon, 21 Apr 2025 16:09:26 -0700 Subject: [PATCH 4/5] update tests --- .../swing/JTable/InternationalCharacters.java | 6 ------ test/jdk/javax/swing/JTable/bug4118307.java | 20 +++++++++---------- test/jdk/javax/swing/JTable/bug4138158.java | 10 +++++----- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/test/jdk/javax/swing/JTable/InternationalCharacters.java b/test/jdk/javax/swing/JTable/InternationalCharacters.java index f9665a22b7295..1d8fc2c4576e0 100644 --- a/test/jdk/javax/swing/JTable/InternationalCharacters.java +++ b/test/jdk/javax/swing/JTable/InternationalCharacters.java @@ -165,12 +165,6 @@ public void setValue(Object value) { scrollpane.setBorder(new BevelBorder(BevelBorder.LOWERED)); scrollpane.setPreferredSize(new Dimension(430, 200)); - WindowListener l = new WindowAdapter() { - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }; - frame.addWindowListener(l); frame.add(scrollpane); frame.setSize(500, 200); return frame; diff --git a/test/jdk/javax/swing/JTable/bug4118307.java b/test/jdk/javax/swing/JTable/bug4118307.java index d878be80b14c2..537e92176efa7 100644 --- a/test/jdk/javax/swing/JTable/bug4118307.java +++ b/test/jdk/javax/swing/JTable/bug4118307.java @@ -47,7 +47,7 @@ public class bug4118307 { static MyTable tbl; static Point tableLoc; static Point p; - private static boolean flag = false; + private static volatile boolean flag; static final String[] columnNames = {"Integer", "Double"}; static final Object[][] data = { {5, 3.14}, @@ -62,6 +62,7 @@ public static void main(String[] args) throws Exception { robot.setAutoDelay(250); SwingUtilities.invokeAndWait(() -> createTestUI()); robot.waitForIdle(); + robot.delay(1000); SwingUtilities.invokeAndWait(() -> { tableLoc = tbl.getLocationOnScreen(); @@ -105,7 +106,7 @@ public static void main(String[] args) throws Exception { robot.waitForIdle(); robot.delay(5000); - if (isFail()) { + if (!flag) { throw new RuntimeException("Test Failed."); } } finally { @@ -122,20 +123,14 @@ public static void createTestUI() { MyTableModel myModel = new MyTableModel(); tbl = new MyTable(myModel); JScrollPane sp = new JScrollPane(tbl); + flag = true; + frame.add(sp, BorderLayout.CENTER); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } - static synchronized void setFail() { - flag = true; - } - - static synchronized boolean isFail() { - return flag; - } - static class MyTable extends JTable { public MyTable(TableModel tm) { super(tm); @@ -146,7 +141,7 @@ public Component prepareRenderer(TableCellRenderer rend, int row, int col) { return super.prepareRenderer(rend, row, col); } catch (Exception e) { e.printStackTrace(); - setFail(); + flag = false; return null; } } @@ -161,6 +156,7 @@ public int getRowCount() { return data.length; } + @Override public String getColumnName(int col) { return columnNames[col]; } @@ -173,10 +169,12 @@ public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } + @Override public boolean isCellEditable(int row, int col) { return true; } + @Override public void setValueAt(Object value, int row, int col) { data[row][col] = value; } diff --git a/test/jdk/javax/swing/JTable/bug4138158.java b/test/jdk/javax/swing/JTable/bug4138158.java index f728ec0a923a4..25a1a60179643 100644 --- a/test/jdk/javax/swing/JTable/bug4138158.java +++ b/test/jdk/javax/swing/JTable/bug4138158.java @@ -31,14 +31,14 @@ * @summary Tests that setAutoscrolls(false) locks autoscroll * @library /java/awt/regtesthelpers * @build PassFailJFrame - * @run main/manual bug4138158 + * @run main bug4138158 */ public class bug4138158 { private static final String INSTRUCTIONS = """ - Move mouse to beginning of table, press left mouse button and move mouse down - so that mouse cursor is below the bottom border of table. If the table isn't - scrolled down then test passes. If the table is scrolled then test fails. + Move mouse to beginning of table, press left mouse button and drag mouse down + below the frame. If the table isn't scrolled down then test passes. + If the table is scrolled then test fails. """; public static void main(String[] args) throws Exception { @@ -56,7 +56,7 @@ public static JFrame createTestUI() { table.setAutoscrolls(false); JScrollPane sp = new JScrollPane(table); frame.add(sp); - frame.pack(); + frame.setSize(200, 200); return frame; } } From 94446eee69da8ee7856fa9d2e470294c1410647f Mon Sep 17 00:00:00 2001 From: Alisen Chung Date: Mon, 21 Apr 2025 16:13:39 -0700 Subject: [PATCH 5/5] manual --- test/jdk/javax/swing/JTable/bug4138158.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/javax/swing/JTable/bug4138158.java b/test/jdk/javax/swing/JTable/bug4138158.java index 25a1a60179643..400b8b1952ef0 100644 --- a/test/jdk/javax/swing/JTable/bug4138158.java +++ b/test/jdk/javax/swing/JTable/bug4138158.java @@ -31,7 +31,7 @@ * @summary Tests that setAutoscrolls(false) locks autoscroll * @library /java/awt/regtesthelpers * @build PassFailJFrame - * @run main bug4138158 + * @run main/manual bug4138158 */ public class bug4138158 {