JDK-4130823 : Not painting focus when the radio button has only icon
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-04-20
  • Updated: 2017-05-23
Related Reports
Relates :  
Relates :  
Description
If JRadioButton has only icon(without text), painting focus around the icon is not drawn. 

Steps)
1. Run SwingSet
2. Select 'RadioButtons' tab.
3. Make sure paintborder is unchecked and paintfocus is checked.
4. Click buttons.
5. You will see image button is not painting focus.

This looks like intentional after investigating BasicRadioButtonUI.java. It paints focus only when it has texts(ln#162)
I suggests painting focus even the radio button has only icon and the reasons are:

"setFocusPainted(true) should be working no matter what text or icon contents"   
bae-chul.kim@eng 1998-04-20

Comments
SUGGESTED FIX Let's paint focus around textRect, if button has text, and around iconRect otherwise: *** C:\TMP\geta296 Tue Dec 19 13:41:16 2000 --- BasicRadioButtonUI.java Tue Dec 19 13:41:13 2000 *************** *** 162,172 **** v.paint(g, textRect); } else { paintText(g, b, textRect, text); - if(b.hasFocus() && b.isFocusPainted() && - textRect.width > 0 && textRect.height > 0 ) { - paintFocus(g, textRect, size); - } } } } --- 162,175 ---- v.paint(g, textRect); } else { paintText(g, b, textRect, text); } + } + if (b.hasFocus() && b.isFocusPainted()) { + if (textRect.width > 0 && textRect.height > 0) { + paintFocus(g, textRect, size); + } else { + paintFocus(g, iconRect, size); + } } } ------- MetalRadioButtonUI.java ------- *** /tmp/dPFKdw_ Thu Feb 24 12:23:54 2000 --- MetalRadioButtonUI.java Fri Feb 18 12:32:09 2000 *************** *** 182,193 **** textRect.x, textRect.y + fm.getAscent()); } - if(b.hasFocus() && b.isFocusPainted() && - textRect.width > 0 && textRect.height > 0 ) { - paintFocus(g,textRect,size); - } } } } protected void paintFocus(Graphics g, Rectangle t, Dimension d){ --- 182,197 ---- textRect.x, textRect.y + fm.getAscent()); } } } + + if (b.hasFocus() && b.isFocusPainted()) { + if (textRect.width > 0 && textRect.height > 0) { + paintFocus(g, textRect, size); + } else { + paintFocus(g, iconRect, size); + } + } } protected void paintFocus(Graphics g, Rectangle t, Dimension d){
28-09-2004

EVALUATION Yup. Seems worth fixing at some point. steve.wilson@eng 1998-05-28 Focus is painted only when the button has text (BasicRadioButtonUI.java): if(b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0 ) { paintFocus(g, textRect, size); } ###@###.### 2000-02-24
24-02-2000