Skip to content

Commit

Permalink
8348760: RadioButton is not shown if JRadioButtonMenuItem is rendered…
Browse files Browse the repository at this point in the history
… with ImageIcon in WindowsLookAndFeel
  • Loading branch information
prsadhuk committed Jan 28, 2025
1 parent a0b7c4f commit 06c1d44
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* 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
Expand Down Expand Up @@ -857,8 +857,7 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
State backgroundState;
State state;
if (isEnabled(c, null)) {
backgroundState =
(icon != null) ? State.BITMAP : State.NORMAL;
backgroundState = State.NORMAL;
state = (type == JRadioButtonMenuItem.class)
? State.BULLETNORMAL
: State.CHECKMARKNORMAL;
Expand All @@ -878,12 +877,47 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
if (icon == null) {
skin = xp.getSkin(c, part);
skin.paintSkin(g, x + OFFSET, y + OFFSET, state);
} else {
skin = xp.getSkin(c, part);
skin.paintSkin(g, x - 3*OFFSET, y + OFFSET, state);
}
}
}
}
if (icon != null) {
icon.paintIcon(c, g, x + OFFSET, y + OFFSET);
if (!((AbstractButton)c).isSelected()) {
Part backgroundPart = Part.MP_POPUPCHECKBACKGROUND;
Part part;
if (type == JRadioButtonMenuItem.class) {
part = Part.BP_RADIOBUTTON;
} else {
part = Part.MP_POPUPCHECK;
}
State backgroundState;
State state;
if (isEnabled(c, null)) {
backgroundState = State.NORMAL;
state = (type == JRadioButtonMenuItem.class)
? State.BULLETNORMAL
: State.CHECKMARKNORMAL;
} else {
backgroundState = State.DISABLEDPUSHED;
state =
(type == JRadioButtonMenuItem.class)
? State.BULLETDISABLED
: State.CHECKMARKDISABLED;
}
XPStyle xp = XPStyle.getXP();
if (xp != null) {
Skin skin;
skin = xp.getSkin(c, backgroundPart);
skin.paintSkin(g, x, y,
getIconWidth(), getIconHeight(), backgroundState);
skin = xp.getSkin(c, part);
skin.paintSkin(g, x - 2 * OFFSET, y + OFFSET, state);
}
}
icon.paintIcon(c, g, x + 3*OFFSET, y + OFFSET);
}
}
private static WindowsMenuItemUIAccessor getAccessor(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 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 8348760
* @summary Verify if RadioButton is shown if JRadioButtonMenuItem
* is rendered with ImageIcon in WindowsLookAndFeel
* @requires (os.family == "windows")
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual TestImageIconWithJRadioButtonMenuItem
*/

import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.UIManager;

public class TestImageIconWithJRadioButtonMenuItem {

private static final String instructionsText = """
Two JRadioButtonMenuItem will be shown.
One JRadioButtonMenuItem is with imageIcon and
another one without imageicon.
Verify that for JRadioButtonMenuItem with imageicon,
radiobutton is been shown alongside the imageicon.
If radiobutton is shown, test passes else fails.""";

public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
PassFailJFrame.builder()
.title("JRadioButtonMenuItem Instructions")
.instructions(instructionsText)
.rows(10)
.columns(40)
.testUI(TestImageIconWithJRadioButtonMenuItem::doTest)
.build()
.awaitAndCheck();
}

public static JFrame doTest() {
String imgPath1 = "./duke.gif";

JFrame frame = new JFrame("RadioButtonWithImageIcon");
ImageIcon imageIcon1 = new ImageIcon(imgPath1);
AbstractButton button1 = new JRadioButtonMenuItem("JRadioButtonMenuItem 1",
imageIcon1);
button1.setSelected(true);
AbstractButton button2 = new JRadioButtonMenuItem("JRadioButtonMenuItem 2");

ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(button1);
buttonGroup.add(button2);

JPanel panel = new JPanel();
panel.add(button1);
panel.add(button2);

frame.getContentPane().add(panel);
frame.pack();
return frame;
}
}
Binary file added test/jdk/javax/swing/JMenuItem/duke.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06c1d44

Please sign in to comment.