Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8353486 : Open source Swing Tests - Set 4 #24456

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions test/jdk/javax/swing/JFileChooser/bug4464774.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2003, 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.
*/

/*
* @test
* @bug 4464774
* @requires (os.family == "windows")
* @summary JFileChooser: selection of left-side folder buttons shown incorrectly
in Windows L&F
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4464774
*/

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class bug4464774 {
private static final String INSTRUCTIONS = """
Click on "Show JFileChooser" button below to display
a JFileChooser dialog.
Click any button from the buttons to the left
("Documents", "Desktop", "My Computer" etc.) in FileChooser dialog.
When the button is toggled, it should be lowered and
should not have focus painted inside it (black dotted frame).

If the above is true, press PASS else FAIL.
""";

public static void main(String[] argv) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
PassFailJFrame.builder()
.title("JFileChooser Instructions")
.instructions(INSTRUCTIONS)
.rows(10)
.columns(65)
.splitUIBottom(bug4464774::createAndShowUI)
.build()
.awaitAndCheck();
}

public static JPanel createAndShowUI() {
JButton button = new JButton("Show JFileChooser");
button.addActionListener(e -> {
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(null);
});
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.setPreferredSize(new Dimension(200, 50));
p.add(button);
return p;
}
}
77 changes: 77 additions & 0 deletions test/jdk/javax/swing/JFileChooser/bug4522756.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2002, 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.
*/

/* @test
@bug 4522756
@requires (os.family == "windows")
@summary To verify that if for the first time JFileChooser is opened,
the icon for Desktop is not missing.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4522756
*/

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class bug4522756 {
private static final String INSTRUCTIONS = """
Click on "Show JFileChooser" button below and verify the following:

1. If Desktop icon image is present on the Desktop button
on the left panel of JFileChooser.
2. Press Desktop button. Check that you actually
go up to the desktop.

If the above is true press PASS else FAIL.
""";

public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
PassFailJFrame.builder()
.title("Instructions")
.instructions(INSTRUCTIONS)
.rows(12)
.columns(50)
.splitUIBottom(bug4522756::createAndShowUI)
.build()
.awaitAndCheck();
}

public static JPanel createAndShowUI() {
JButton button = new JButton("Show JFileChooser");
button.addActionListener(e -> {
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(null);
});
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.setPreferredSize(new Dimension(200, 50));
p.add(button);
return p;
}
}
123 changes: 123 additions & 0 deletions test/jdk/javax/swing/JFileChooser/bug4759934.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (c) 2003, 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.
*/

/*
* @test
* @key headful
* @bug 4759934
* @summary windows activation problem
* @library /javax/swing/regtesthelpers
* @build Util
* @run main bug4759934
*/

import java.awt.Dialog;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class bug4759934 {
private static JFrame fr;
private static Dialog dlg;
private static JFileChooser jfc;

private static JButton frameBtn;
private static JButton dialogBtn;

public static void main(String[] args) throws Exception {
try {
Robot robot = new Robot();
robot.setAutoWaitForIdle(true);
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(bug4759934::createTestUI);
robot.waitForIdle();
robot.delay(1000);

Point frameBtnLoc = Util.getCenterPoint(frameBtn);
robot.mouseMove(frameBtnLoc.x, frameBtnLoc.y);
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
robot.delay(500);

Point dlgBtnLoc = Util.getCenterPoint(dialogBtn);
robot.mouseMove(dlgBtnLoc.x , dlgBtnLoc.y);
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
robot.delay(500);

robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
robot.delay(500);

SwingUtilities.invokeAndWait(() -> {
if (frameBtn.hasFocus() && !dialogBtn.hasFocus()) {
throw new RuntimeException("Test failed! Focus was passed back" +
" to Frame instead of Dialog");
}
});
} finally {
SwingUtilities.invokeAndWait(() -> {
if (dlg != null) {
dlg.dispose();
}
if (fr != null) {
fr.dispose();
}
});
}
}

private static void createTestUI() {
fr = new JFrame("bug4759934 - JFrame");

frameBtn = new JButton("Show Dialog");
fr.add(frameBtn);

frameBtn.addActionListener(e -> createDialog());
fr.setSize(300, 200);
fr.setLocationRelativeTo(null);
fr.setVisible(true);
}

private static void createDialog() {
dlg = new JDialog(fr, "bug4759934 - JDialog");

dialogBtn = new JButton("Show FileChooser");
dlg.add(dialogBtn);

dialogBtn.addActionListener(e -> {
jfc = new JFileChooser();
jfc.showOpenDialog(dlg);
});

dlg.setSize(300, 200);
dlg.setLocation(fr.getX() + fr.getWidth() + 10, fr.getY());
dlg.setVisible(true);
}
}
Loading