JDK-4129691 : Motif,JButton:If paintBorder is false focus not painting though paintfocus true
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-04-16
  • Updated: 2004-04-23
  • Resolved: 2004-04-23
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
"Painting focus and painting border should be independent"

In motif look, JButton's paint focus is dependent on the its border. 
If paintBorder is false, painting focus is never done no matter what paintFocus 
is true. (In metal and window look, they handled paintBorder and paintFocus 
independently.)

See the paintFocus() method of MotifButtonUI and paintBorder() method of ButtonBorder class in MotifBorderFactory.
bae-chul.kim@eng 1998-04-16

Please see "Suggested Fix"
bae-chul.kim@eng 1998-04-17

Comments
SUGGESTED FIX General solution would be: If paintBorder is true, the border should handle painting focus. -PART ONE If paintBorder is false, each button's UI should handle painting focus. - PART TWO PART ONE: See Bug#4129699's "Suggeted Fix" PART TWO: //From MotifButtonUI.java protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){ // focus painting is handled by the border // add following if(!b.isBorderPainted()){ Dimension d = b.getSize(); g.setColor( UIManager.getColor("RadioButton.focus")); g.drawRect(0,0,d.width-1,d.height-1); } } Those two changes will make sence more and behavior of painting border/focus will be same mechnism with metal/window look. bae-chul.kim@eng 1998-04-17 All right, but we should also handle default buttons: ------- MotifBorders.java ------- *** /tmp/d0hej.r Thu Feb 17 19:29:37 2000 --- MotifBorders.java Thu Feb 17 18:45:41 2000 *************** *** 124,131 **** ButtonModel model = b.getModel(); isPressed = (model.isArmed() && model.isPressed()); ! hasFocus = (model.isArmed() && isPressed) || ! (b.isFocusPainted() && b.hasFocus()); if (b instanceof JButton) { canBeDefault = ((JButton)b).isDefaultCapable(); isDefault = ((JButton)b).isDefaultButton(); --- 124,130 ---- ButtonModel model = b.getModel(); isPressed = (model.isArmed() && model.isPressed()); ! hasFocus = b.isFocusPainted() && (isPressed || b.hasFocus()); if (b instanceof JButton) { canBeDefault = ((JButton)b).isDefaultCapable(); isDefault = ((JButton)b).isDefaultButton(); ------- MotifButtonUI.java ------- *** /tmp/dYH99h_ Thu Feb 17 19:29:54 2000 --- MotifButtonUI.java Thu Feb 17 19:17:43 2000 *************** *** 85,94 **** super.paint(g,c); } ! protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){ ! // focus painting is handled by the border } ! protected void paintButtonPressed(Graphics g, AbstractButton b) { fillContentArea( g, b , selectColor ); --- 85,127 ---- super.paint(g,c); } ! protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, ! Rectangle textRect, Rectangle iconRect) { ! // focus painting is handled by the border, unless it is not painted ! ! if (!b.isBorderPainted()) { ! boolean canBeDefault = false; ! boolean isDefault = false; ! ! if (b instanceof JButton) { ! JButton jButton = (JButton)b; ! canBeDefault = jButton.isDefaultCapable(); ! isDefault = jButton.isDefaultButton(); ! } ! ! int w = b.getWidth(); ! int h = b.getHeight(); ! int x1 = 0; ! int y1 = 0; ! int w1 = w-1; ! int h1 = h-1; ! ! if (canBeDefault) { ! x1 +=6; ! y1 += 6; ! w1 -= 12; ! h1 -= 12; ! } ! ! g.setColor(UIManager.getColor("activeCaptionBorder")); ! if (isDefault) { ! g.drawRect(0, 0, w-1, h-1); ! } else { ! g.drawRect(x1, y1, w1, h1); ! } ! } } ! protected void paintButtonPressed(Graphics g, AbstractButton b) { fillContentArea( g, b , selectColor ); ###@###.### 2000-02-23
23-02-2000

EVALUATION Yup. This is a bug. Just a clarification, the submitter wrote Metal several times when he meant Motif. This is a Motif L&F only bug. The suggested fix looks pretty fair as well. steve.wilson@eng 1998-05-27
27-05-1998