Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 1999, 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 4210461
* @summary Confirm Metal Look & Feel's MenuItem Accelerator Delimiter
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual JavaLAFMenuAcceleratorDelimiter
*/

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.UIManager;

public class JavaLAFMenuAcceleratorDelimiter {
static final String INSTRUCTIONS = """
A simple check. The visual design specification for JLF/Metal asks for
a "-" to delimit the other two entities in a menu item's accelerator.
The test passes if the delimiter for the accelerator is correct when
opening the example menu. Otherwise, the test fails.
""";

public static void main(String[] args) throws Exception {
// Set Metal L&F
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
PassFailJFrame.builder()
.title("JavaLAFMenuAcceleratorDelimiter Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(JavaLAFMenuAcceleratorDelimiter::createUI)
.build()
.awaitAndCheck();
}

static JFrame createUI() {
JFrame frame = new JFrame("Metal L&F Accelerator Delimiter Test");
JPanel menuPanel = new JPanel();
JMenuBar menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu exampleMenu = new JMenu("Example");
JMenuItem hiMenuItem = new JMenuItem("Hi There!");
hiMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,
ActionEvent.CTRL_MASK));
exampleMenu.add(hiMenuItem);
menuBar.add(exampleMenu);
menuPanel.add(menuBar);

frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(menuPanel, BorderLayout.CENTER);
frame.setSize(250, 150);
return frame;
}
}
98 changes: 98 additions & 0 deletions test/jdk/javax/swing/plaf/metal/MetalIconFactory/bug4952462.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2004, 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 4952462
* @summary Ocean: Tests that disabled selected JRadioButton dot is NOT
* painted with the foreground color
* @modules java.desktop/sun.awt
* @library /test/lib
* @key headful
* @run main bug4952462
*/

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.Robot;

import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalTheme;

import jtreg.SkippedException;
import sun.awt.AppContext;

public class bug4952462 {
private static JFrame frame;
private static JRadioButton rb;

public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

MetalTheme theme = (MetalTheme) AppContext.getAppContext().get("currentMetalTheme");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of AppContext can be dropped, and replaced by some other public api.

if (theme == null || !"Ocean".equals(theme.getName())) {
throw new SkippedException("Current theme is not Ocean. Test is " +
"only for Metal's Ocean theme. Skipping test.");
} else {
Robot r = new Robot();
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame("Metal JRadioButton Foreground Color Test");
frame.getContentPane().setLayout(new FlowLayout());
rb = new JRadioButton("RadioButton", true);
rb.setEnabled(false);
rb.setForeground(Color.RED);
frame.getContentPane().add(rb);
frame.setSize(250, 100);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});

r.waitForIdle();
r.delay(500);

SwingUtilities.invokeAndWait(() -> {
Point p = rb.getLocationOnScreen();
for (int i = 0; i < 50; i++) {
Color c = r.getPixelColor(p.x + 10 + i, p.y + (rb.getHeight() / 2));
System.out.println(c);
if (c.getRed() > 200 && c.getBlue() < 200 && c.getGreen() < 200) {
throw new RuntimeException("Test failed. Radiobutton is red " +
"and not grey.");
}
}
});
}
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2001, 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 4186347
* @summary Tests changing Slider.horizontalThumbIcon UIResource
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4186347
*/

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.IconUIResource;

public class bug4186347 {
static final String INSTRUCTIONS = """
If the slider's thumb icon is painted correctly
(that is centered vertically relative to slider
channel) then test passed, otherwise it failed.
""";

public static void main(String[] args) throws Exception {
// Set Metal L&F
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
PassFailJFrame.builder()
.title("bug4186347 Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(bug4186347::createUI)
.build()
.awaitAndCheck();
}

static JFrame createUI() {
JFrame frame = new JFrame("Metal JSlider Icon Test");
String a = System.getProperty("test.src", ".")
+ System.getProperty("file.separator")
+ "duke.gif";
Icon icon = new ImageIcon(a);
IconUIResource iconResource = new IconUIResource(icon);
UIDefaults defaults = UIManager.getDefaults();
defaults.put("Slider.horizontalThumbIcon", iconResource);
JSlider s = new JSlider();
frame.getContentPane().add(s);
frame.setSize(250, 150);
return frame;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading