JDK-4130798 : MotifRadioButtonUI: paintFocus() method needs more careful logic
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-04-20
  • Updated: 2006-11-14
  • Resolved: 2006-11-14
Related Reports
Relates :  
Description
The method, paintFocus() of MotifRadioButtonUI.java is called whenver isFocusPainted is true and hasFocus is true. Sounds good but painting focus is also handled by its border when isBorderPainted is true. As a result of that painting focus is done twice when isBorderPainted is true;

by paintFocus of MotifRadioButtonUI and 
by its ToggleButtonBorder defined in MotifBorderFactory.java

Please see 'Suggested Fix' tab.
bae-chul.kim@eng 1998-04-20

Comments
EVALUATION Motif L&F is very out of date and not very useful any more. As such, there's little benefit to doing anything with this bug. Closing as "Will Not Fix".
14-11-2006

EVALUATION It does appear to be drawing redundant information. One should be removed. sky 1998-06-01 Name: ibR10256 Date: 04/23/2004 Now BasicBorders.RadioButtonBorder is used for JRadioButton and JCheckBox in Motif but as all the Basic borders it doesn't paint the focus indicator (it paints only a black rectangle which is not visible when the button is pressed). Also this border overwrites the focus indicator painted in MotifRadioButton.paintFocus(). Therefore I suggest to use better MotifBorders.ToggleButtonBorder and then to apply the fix suggested by ###@###.###. ###@###.### 2004-04-23 ======================================================================
28-09-2004

SUGGESTED FIX This method would better be called only when isBorderPainted is false and b.hasFocus() && b.isFocusPainted() is true. Since paintFocus() of MotifRadioButton doesn't have enough information to see the button's isBorderPainted() is true or not, let's change its super class's paint method. From the BasicRadioButtonUI's paint(), line number 162; if(b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0) { paintFocus(g,textRect,size); } <Suggested Fix> if(!b.isBorderPainted() && b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0 ) { paintFocus(g,textRect,size); } bae-chul.kim@eng 1998-04-20 This means to make Basic LAF assume that focus is painted by the button border. This is true for Motif only. Instead i suggest to rewrite BasicRadioButtonUI.paint() to call another paintFocus() method, which is passed reference to AbstractButton. This requires changes in all BasicRadioButtonUI subclasses, including WindowsRadioButtonUI and MotifRadioButtonUI: ------- BasicRadioButtonUI.java ------- *** /tmp/dPwIo8_ Thu Mar 2 12:29:02 2000 --- BasicRadioButtonUI.java Thu Mar 2 12:27:01 2000 *************** *** 180,191 **** } if(b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0 ) { ! paintFocus(g, textRect, size); } } } } protected void paintFocus(Graphics g, Rectangle textRect, Dimension size){ } --- 180,198 ---- } if(b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0 ) { ! paintFocus(g, b, viewRect, textRect, iconRect); } } } } + protected void paintFocus(Graphics g, AbstractButton b, + Rectangle viewRect, Rectangle textRect, Rectangle iconRect) { + } + + /* This method is no longer being called. It is replaced with + * paintFocus(Graphics, AbstractButton, Rectangle, Rectangle, Rectangle) + */ protected void paintFocus(Graphics g, Rectangle textRect, Dimension size){ } ------- MotifRadioButtonUI.java ------- *** /tmp/d0l8EmZ Thu Mar 2 12:28:14 2000 --- MotifRadioButtonUI.java Thu Mar 2 12:27:04 2000 *************** *** 74,79 **** --- 74,92 ---- // ******************************** // Paint Methods // ******************************** + protected void paintFocus(Graphics g, AbstractButton b, + Rectangle viewRect, Rectangle textRect, Rectangle iconRect) { + + if (!b.isBorderPainted()) { + Dimension d = b.getSize(); + g.setColor(getFocusColor()); + g.drawRect(0, 0, d.width-1, d.height-1); + } + } + + /* This method is no longer being called. It is replaced with + * paintFocus(Graphics, AbstractButton, Rectangle, Rectangle, Rectangle) + */ protected void paintFocus(Graphics g, Rectangle t, Dimension d){ g.setColor(getFocusColor()); g.drawRect(0,0,d.width-1,d.height-1); ------- WindowsRadioButtonUI.java ------- *** /tmp/dnAmDU_ Thu Mar 2 12:28:34 2000 --- WindowsRadioButtonUI.java Thu Mar 2 12:27:11 2000 *************** *** 69,78 **** // ******************************** // Paint Methods // ******************************** protected void paintFocus(Graphics g, Rectangle textRect, Dimension d){ g.setColor(getFocusColor()); BasicGraphicsUtils.drawDashedRect(g, textRect.x, textRect.y, textRect.wi dth, textRect.height); ! } } --- 69,88 ---- // ******************************** // Paint Methods // ******************************** + protected void paintFocus(Graphics g, AbstractButton b, + Rectangle viewRect, Rectangle textRect, Rectangle iconRect) { + + g.setColor(getFocusColor()); + BasicGraphicsUtils.drawDashedRect(g, textRect.x, textRect.y, textRect.wi dth, textRect.height); + } + + /* This method is no longer being called. It is replaced with + * paintFocus(Graphics, AbstractButton, Rectangle, Rectangle, Rectangle) + */ protected void paintFocus(Graphics g, Rectangle textRect, Dimension d){ g.setColor(getFocusColor()); BasicGraphicsUtils.drawDashedRect(g, textRect.x, textRect.y, textRect.wi dth, textRect.height); ! } } ###@###.### 2000-03-02
02-03-2000