JDK-4252164 : Rounded Line Borders Don't Render Properly (fix included)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 1999-07-07
  • Updated: 2014-04-28
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b15Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Name: sg39081			Date: 07/07/99


The Swing LineBorder doesn't draw rounded borders properly.
The following change fixes the problem:

In javax.swing.border.LineBorder.java in paintBorder(), replace:

  for(i = 0; i < thickness; i++)  {
    if(!roundedCorners)
      g.drawRect(x+i, y+i, width-i-i-1, height-i-i-1);
    else
      g.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, thickness, thickness);
  }

with

  if(!roundedCorners) {
    for(i = 0; i < thickness; i++) {
      g.drawRect(x+i, y+i, width-i-i-1, height-i-i-1);
    }
  } else {
    g.fillRoundRect(x,y,width,thickness,thickness,thickness);
    g.fillRoundRect(x,y+height-thickness,width,thickness,thickness,thickness);
    g.fillRoundRect(x,y,thickness,height,thickness,thickness);
    g.fillRoundRect(x+width-thickness,y,thickness,height,thickness,thickness);

  }
(Review ID: 55026) 
======================================================================

Name: apC97674			Date: 11/04/99


----------------Test------------------------------
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

public class bug4252164 extends JFrame {
    
    public static void main(String[] args) {
	JFrame jf = new JFrame("Focus Test");
	jf.getContentPane().setLayout(new FlowLayout());

	LineBorder brdr = new LineBorder(Color.blue, 7, true);
	JButton bt = new JButton("Do Nothing");
	bt.setBorder(brdr);
		
	jf.getContentPane().add(bt);
	jf.setSize(200,200);
	jf.setVisible(true);
    }   
}
-------------------------------------------------------
###@###.###
======================================================================

Comments
EVALUATION Contributed code works incorrectly because inner shape of border is not rounded. We should use Java2D instead.
23-03-2007

EVALUATION Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=11483&forumID=1463
16-02-2006

WORK AROUND Name: sg39081 Date: 07/07/99 Use the code above to write your own border class. ======================================================================
25-09-2004

SUGGESTED FIX Name: apC97674 Date: 11/04/99 Fix suggested by submitter work correctly. ======================================================================
25-09-2004