-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8348760: RadioButton is not shown if JRadioButtonMenuItem is rendered with ImageIcon in WindowsLookAndFeel #23324
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
base: master
Are you sure you want to change the base?
Changes from all commits
06c1d44
bc5580f
befbdf5
2bb0869
9aeda88
4a5a779
6a8faec
9482b26
6a9f914
f9cb299
d5a252b
31cdc70
cdcd7d0
5742db5
46a1cb5
7fac9e0
7cb51be
7f0849f
de139e5
9a45719
a3475a9
3887606
00daa8f
b5a91f5
03a0872
381cdf5
2ff5f03
e20cfc0
ba7ecae
bfc108e
898996a
f019f63
ea1016f
2348548
24fb819
fcaeb2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||
/* | ||||||||||
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. | ||||||||||
* 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 | ||||||||||
|
@@ -26,22 +26,30 @@ | |||||||||
package com.sun.java.swing; | ||||||||||
|
||||||||||
import java.applet.Applet; | ||||||||||
import java.awt.Color; | ||||||||||
import java.awt.Component; | ||||||||||
import java.awt.Container; | ||||||||||
import java.awt.Graphics; | ||||||||||
import java.awt.Graphics2D; | ||||||||||
import java.awt.Insets; | ||||||||||
import java.awt.Rectangle; | ||||||||||
import java.awt.Stroke; | ||||||||||
import java.awt.Window; | ||||||||||
import java.awt.geom.AffineTransform; | ||||||||||
import java.util.Collections; | ||||||||||
import java.util.Map; | ||||||||||
import java.util.WeakHashMap; | ||||||||||
|
||||||||||
import javax.swing.ButtonModel; | ||||||||||
import javax.swing.Icon; | ||||||||||
import javax.swing.JComponent; | ||||||||||
import javax.swing.JMenu; | ||||||||||
import javax.swing.RepaintManager; | ||||||||||
|
||||||||||
import sun.awt.AppContext; | ||||||||||
import sun.awt.SunToolkit; | ||||||||||
import sun.swing.MenuItemLayoutHelper; | ||||||||||
import sun.swing.SwingUtilities2; | ||||||||||
|
||||||||||
import static sun.java2d.pipe.Region.clipRound; | ||||||||||
|
||||||||||
|
@@ -64,6 +72,10 @@ public class SwingUtilities3 { | |||||||||
private static final Object DELEGATE_REPAINT_MANAGER_KEY = | ||||||||||
new StringBuilder("DelegateRepaintManagerKey"); | ||||||||||
|
||||||||||
private static Color disabledForeground; | ||||||||||
private static Color acceleratorSelectionForeground; | ||||||||||
private static Color acceleratorForeground; | ||||||||||
|
||||||||||
/** | ||||||||||
* Registers delegate RepaintManager for {@code JComponent}. | ||||||||||
*/ | ||||||||||
|
@@ -143,6 +155,128 @@ public static RepaintManager getDelegateRepaintManager(Component | |||||||||
return delegate; | ||||||||||
} | ||||||||||
|
||||||||||
public static void applyInsets(Rectangle rect, Insets insets) { | ||||||||||
prsadhuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
if (insets != null) { | ||||||||||
rect.x += insets.left; | ||||||||||
rect.y += insets.top; | ||||||||||
rect.width -= (insets.right + rect.x); | ||||||||||
rect.height -= (insets.bottom + rect.y); | ||||||||||
Comment on lines
+162
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The formula doesn't look right. Why do you subtract This would work correctly if both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was the same calculation used in Similarly other SwingUtilities3 changes are also as it was in BasicMenuItemUI, it was just moved verbatim from BasicMenuItemUI to it so that it can be called from both Basic and WindowsMenuItemUI class with no changes..nothing more and nothing less...probably it can be optimized but I wanted to keep the call and the content in each method in SwingUtilities3 same as it was in BasicMenuItemUI |
||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
public static void paintCheckIcon(Graphics g, MenuItemLayoutHelper lh, | ||||||||||
prsadhuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
MenuItemLayoutHelper.LayoutResult lr, | ||||||||||
Color holdc, Color foreground) { | ||||||||||
if (lh.getCheckIcon() != null) { | ||||||||||
ButtonModel model = lh.getMenuItem().getModel(); | ||||||||||
if (model.isArmed() || (lh.getMenuItem() instanceof JMenu | ||||||||||
&& model.isSelected())) { | ||||||||||
g.setColor(foreground); | ||||||||||
} else { | ||||||||||
g.setColor(holdc); | ||||||||||
} | ||||||||||
if (lh.useCheckAndArrow()) { | ||||||||||
lh.getCheckIcon().paintIcon(lh.getMenuItem(), g, | ||||||||||
lr.getCheckRect().x, lr.getCheckRect().y); | ||||||||||
} | ||||||||||
g.setColor(holdc); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
public static void paintIcon(Graphics g, MenuItemLayoutHelper lh, | ||||||||||
MenuItemLayoutHelper.LayoutResult lr, Color holdc) { | ||||||||||
if (lh.getIcon() != null) { | ||||||||||
Icon icon; | ||||||||||
ButtonModel model = lh.getMenuItem().getModel(); | ||||||||||
if (!model.isEnabled()) { | ||||||||||
icon = lh.getMenuItem().getDisabledIcon(); | ||||||||||
} else if (model.isPressed() && model.isArmed()) { | ||||||||||
icon = lh.getMenuItem().getPressedIcon(); | ||||||||||
if (icon == null) { | ||||||||||
// Use default icon | ||||||||||
icon = lh.getMenuItem().getIcon(); | ||||||||||
} | ||||||||||
} else { | ||||||||||
icon = lh.getMenuItem().getIcon(); | ||||||||||
} | ||||||||||
|
||||||||||
if (icon != null) { | ||||||||||
icon.paintIcon(lh.getMenuItem(), g, lr.getIconRect().x, | ||||||||||
lr.getIconRect().y); | ||||||||||
g.setColor(holdc); | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
public static void paintAccText(Graphics g, MenuItemLayoutHelper lh, | ||||||||||
MenuItemLayoutHelper.LayoutResult lr) { | ||||||||||
if (!lh.getAccText().isEmpty()) { | ||||||||||
ButtonModel model = lh.getMenuItem().getModel(); | ||||||||||
g.setFont(lh.getAccFontMetrics().getFont()); | ||||||||||
if (!model.isEnabled()) { | ||||||||||
|
||||||||||
// paint the accText disabled | ||||||||||
if (disabledForeground != null) { | ||||||||||
g.setColor(disabledForeground); | ||||||||||
SwingUtilities2.drawString(lh.getMenuItem(), g, | ||||||||||
lh.getAccText(), lr.getAccRect().x, | ||||||||||
lr.getAccRect().y + lh.getAccFontMetrics().getAscent()); | ||||||||||
} else { | ||||||||||
g.setColor(lh.getMenuItem().getBackground().brighter()); | ||||||||||
SwingUtilities2.drawString(lh.getMenuItem(), g, | ||||||||||
lh.getAccText(), lr.getAccRect().x, | ||||||||||
lr.getAccRect().y + lh.getAccFontMetrics().getAscent()); | ||||||||||
g.setColor(lh.getMenuItem().getBackground().darker()); | ||||||||||
SwingUtilities2.drawString(lh.getMenuItem(), g, | ||||||||||
lh.getAccText(), lr.getAccRect().x - 1, | ||||||||||
lr.getAccRect().y + lh.getFontMetrics().getAscent() - 1); | ||||||||||
} | ||||||||||
} else { | ||||||||||
|
||||||||||
// paint the accText normally | ||||||||||
if (model.isArmed() | ||||||||||
|| (lh.getMenuItem() instanceof JMenu | ||||||||||
&& model.isSelected())) { | ||||||||||
g.setColor(acceleratorSelectionForeground); | ||||||||||
} else { | ||||||||||
g.setColor(acceleratorForeground); | ||||||||||
} | ||||||||||
SwingUtilities2.drawString(lh.getMenuItem(), g, lh.getAccText(), | ||||||||||
lr.getAccRect().x, lr.getAccRect().y + | ||||||||||
lh.getAccFontMetrics().getAscent()); | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
public static void setDisabledForeground(Color disabledFg) { | ||||||||||
disabledForeground = disabledFg; | ||||||||||
} | ||||||||||
|
||||||||||
public static void setAcceleratorSelectionForeground(Color acceleratorSelectionFg) { | ||||||||||
acceleratorForeground = acceleratorSelectionFg; | ||||||||||
} | ||||||||||
|
||||||||||
public static void setAcceleratorForeground(Color acceleratorFg) { | ||||||||||
acceleratorForeground = acceleratorFg; | ||||||||||
} | ||||||||||
|
||||||||||
public static void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh, | ||||||||||
MenuItemLayoutHelper.LayoutResult lr, | ||||||||||
Color foreground) { | ||||||||||
if (lh.getArrowIcon() != null) { | ||||||||||
ButtonModel model = lh.getMenuItem().getModel(); | ||||||||||
if (model.isArmed() || (lh.getMenuItem() instanceof JMenu | ||||||||||
&& model.isSelected())) { | ||||||||||
g.setColor(foreground); | ||||||||||
} | ||||||||||
if (lh.useCheckAndArrow()) { | ||||||||||
lh.getArrowIcon().paintIcon(lh.getMenuItem(), g, | ||||||||||
lr.getArrowRect().x, lr.getArrowRect().y); | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* A task which paints an <i>unscaled</i> border after {@code Graphics} | ||||||||||
* transforms are removed. It's used with the | ||||||||||
|
prsadhuk marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.