Skip to content

Commit acaf2c8

Browse files
author
Damon Nguyen
committedDec 5, 2023
8318590: JButton ignores margin when painting HTML text
Reviewed-by: prr, azvegint, honkar
1 parent d3df3eb commit acaf2c8

File tree

4 files changed

+16
-185
lines changed

4 files changed

+16
-185
lines changed
 

‎src/java.desktop/macosx/classes/com/apple/laf/AquaButtonUI.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,10 @@ public void paint(final Graphics g, final JComponent c) {
338338
}
339339

340340
// performs icon and text rect calculations
341-
final String text;
342-
final Icon icon = b.getIcon();
343-
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
344-
if (v != null && icon == null) {
345-
// use zero insets for HTML without an icon
346-
// since layout only handles text calculations
347-
text = layoutAndGetText(g, b, aquaBorder, new Insets(0,0,0,0),
348-
viewRect, iconRect, textRect);
349-
} else {
350-
text = layoutAndGetText(g, b, aquaBorder, i, viewRect, iconRect, textRect);
351-
}
341+
final String text = layoutAndGetText(g, b, aquaBorder, i, viewRect, iconRect, textRect);
352342

353343
// Paint the Icon
354-
if (icon != null) {
344+
if (b.getIcon() != null) {
355345
paintIcon(g, b, iconRect);
356346
}
357347

@@ -360,6 +350,7 @@ public void paint(final Graphics g, final JComponent c) {
360350
}
361351

362352
if (text != null && !text.isEmpty()) {
353+
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
363354
if (v != null) {
364355
v.paint(g, textRect);
365356
} else {

‎src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonUI.java

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,6 @@
2525

2626
package javax.swing.plaf.basic;
2727

28-
import sun.awt.AppContext;
29-
import sun.swing.SwingUtilities2;
3028
import java.awt.AWTKeyStroke;
3129
import java.awt.Component;
3230
import java.awt.Dimension;
@@ -61,6 +59,9 @@
6159
import javax.swing.plaf.UIResource;
6260
import javax.swing.text.View;
6361

62+
import sun.awt.AppContext;
63+
import sun.swing.SwingUtilities2;
64+
6465
/**
6566
* BasicButton implementation
6667
*
@@ -598,15 +599,7 @@ public Component.BaselineResizeBehavior getBaselineResizeBehavior(
598599

599600
private String layout(AbstractButton b, FontMetrics fm,
600601
int width, int height) {
601-
Insets i;
602-
603-
final View v = (View)b.getClientProperty(BasicHTML.propertyKey);
604-
if (v != null) {
605-
i = new Insets(0, 0, 0, 0);
606-
} else {
607-
i = b.getInsets();
608-
}
609-
602+
Insets i = b.getInsets();
610603
viewRect.x = i.left;
611604
viewRect.y = i.top;
612605
viewRect.width = width - (i.right + viewRect.x);

‎src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java

+8-16
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
package javax.swing.plaf.synth;
2626

27-
import sun.swing.MenuItemLayoutHelper;
28-
import sun.swing.SwingUtilities2;
2927
import java.awt.Color;
3028
import java.awt.Component;
3129
import java.awt.Dimension;
@@ -37,13 +35,15 @@
3735

3836
import javax.swing.ButtonModel;
3937
import javax.swing.Icon;
40-
import javax.swing.JButton;
4138
import javax.swing.JComponent;
4239
import javax.swing.JMenuItem;
4340
import javax.swing.SwingUtilities;
4441
import javax.swing.plaf.basic.BasicHTML;
4542
import javax.swing.text.View;
4643

44+
import sun.swing.MenuItemLayoutHelper;
45+
import sun.swing.SwingUtilities2;
46+
4747
/**
4848
* Wrapper for primitive graphics calls.
4949
*
@@ -392,19 +392,10 @@ public void paintText(SynthContext ss, Graphics g, String text,
392392
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
393393
Insets insets = SynthLookAndFeel.getPaintingInsets(ss, paintInsets);
394394

395-
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
396-
397-
if (c instanceof JButton && v != null) {
398-
paintViewR.x = 0;
399-
paintViewR.y = 0;
400-
paintViewR.width = c.getWidth();
401-
paintViewR.height = c.getHeight();
402-
} else {
403-
paintViewR.x = insets.left;
404-
paintViewR.y = insets.top;
405-
paintViewR.width = c.getWidth() - (insets.left + insets.right);
406-
paintViewR.height = c.getHeight() - (insets.top + insets.bottom);
407-
}
395+
paintViewR.x = insets.left;
396+
paintViewR.y = insets.top;
397+
paintViewR.width = c.getWidth() - (insets.left + insets.right);
398+
paintViewR.height = c.getHeight() - (insets.top + insets.bottom);
408399

409400
paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
410401
paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
@@ -430,6 +421,7 @@ public void paintText(SynthContext ss, Graphics g, String text,
430421
}
431422

432423
if (text != null) {
424+
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
433425
if (v != null) {
434426
v.paint(g, paintTextR);
435427
} else {

‎test/jdk/javax/swing/JButton/HtmlButtonImageTest/HtmlButtonImageTest.java

-145
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.