-
Bug
-
Resolution: Won't Fix
-
P5
-
None
-
1.2.0
-
None
-
x86, sparc
-
generic, solaris_2.5.1
(note: the code below has been tried, it made the problem worse for motif &
windows (fixed metal layout, however))
Hello,
I have found several bugs in the "layout" of JRadioButton/JCheckBox
components, first here is how to repeat the bug using the standard
SwingSet demo (my platform: JDK-1.2fcs-O, NT4.0SP3):
1. Start SwingSet demo.
2. Click on the "RadioButtons" tab
3. Click "Paint Border"
As you can see the layout is not correct.
This bug applies to Metal, Windows and Motif L&F:s.
Same effect can be seen for JCheckBox.
The problem is that *RadioButtonUI.paint methods
doesn't take the Inset into account (as for example
*ButtonUI.paint() does).
For the Windows L&F you need to fix
javax/swing/plaf/basic/BasicRadioButtonUI.java
Here is my patch for Windows/Motif L&F (diff -c):
*** //C/jdk1.2/src/javax/swing/plaf/basic/BasicRadioButtonUI.java Tue Nov 03
16:35:35 1998
--- BasicRadioButtonUI.java Tue Nov 03 19:37:20 1998
***************
*** 95,103 ****
FontMetrics fm = g.getFontMetrics();
size = b.getSize(size);
! viewRect.x = viewRect.y = 0;
! viewRect.width = size.width;
! viewRect.height = size.height;
iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
textRect.x = textRect.y = textRect.width = textRect.height = 0;
--- 95,107 ----
FontMetrics fm = g.getFontMetrics();
size = b.getSize(size);
!
! final Insets i = c.getInsets();
! viewRect.x = i.left;
! viewRect.y = i.top;
! viewRect.width = size.width - (i.right + i.left);
! viewRect.height = size.height - (i.bottom + i.top);
!
iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
textRect.x = textRect.y = textRect.width = textRect.height = 0;
Here is a similar patch for Metal L&F (diff -c):
*** //C/jdk1.2/src/javax/swing/plaf/metal/MetalRadioButtonUI.java Tue Nov 03
16:35:36 1998
--- MetalRadioButtonUI.java Tue Nov 03 19:36:29 1998
***************
*** 106,112 ****
g.setFont(f);
FontMetrics fm = g.getFontMetrics();
! Rectangle viewRect = new Rectangle(size);
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
--- 106,116 ----
g.setFont(f);
FontMetrics fm = g.getFontMetrics();
! final Insets i = c.getInsets();
! Rectangle viewRect = new Rectangle(i.left,
! i.top,
! size.width - (i.right + i.left),
! size.height - (i.bottom + i.top));
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
The above two patches fixes the Windows and Metal L&F:s, but only partially
fixes the Motif L&F. It looks like the person writing the Motif L&F has tried
to compensate for the bugs above.
The bugs are in com/sun/java/swing/plaf/motif/MotifIconFactory.java,
in the CheckBoxIcon and RadioButtonIcon classes.
In the paintIcon methods of these classes the writer has added 2 to the x value
to compensate for the bug above.
In RadioButtonIcon the getIconWidth and getIconHeight methods
returns the value 13. If you take a snapshot of the screen and actually count
the number of pixels drawn by the RadioButtonUI.paintIcon method you will
find that it actually draws 14 pixels.
Here is a patch to fix the remaining Motif L&F problems:
*** //C/jdk1.2/src/com/sun/java/swing/plaf/motif/MotifIconFactory.java Tue Nov 03
16:35:11 1998
--- MotifIconFactory.java Tue Nov 03 19:47:35 1998
***************
*** 125,131 ****
!isArmed &&
isSelected));
- x += 2;
if (checkToggleIn)
{
// toggled from unchecked to checked
--- 125,130 ----
***************
*** 258,266 ****
int w = getIconWidth();
int h = getIconHeight();
- // add pad so focus isn't smudged on the x
- x += 2;
-
boolean isPressed = model.isPressed();
boolean isArmed = model.isArmed();
boolean isEnabled = model.isEnabled();
--- 257,262 ----
***************
*** 331,341 ****
}
public int getIconWidth() {
! return 13;
}
public int getIconHeight() {
! return 13;
}
} // end class RadioButtonIcon
--- 327,337 ----
}
public int getIconWidth() {
! return 14;
}
public int getIconHeight() {
! return 14;
}
} // end class RadioButtonIcon
If you would like the patches in some other form (or even the hacked files),
I will happily send it to you.
Best wishes,
Mats Palmgren
Symsoft AB
SWEDEN
PS.
JDC Bug# 4153357 is fixed with above patches.
- duplicates
-
JDK-4153357 Checkboxes in JDK 1.2Beta4-I SwingSet Demo are being partly erased.
-
- Closed
-
- relates to
-
JDK-4373752 RFE:reopen bug 4187481, Radio and Checkbox buttons not laying out correctly
-
- Closed
-