Skip to main content

Simple LineBorder draws edges with unequal widths

1 reply [Last post]
ecrouse
Offline
Joined: 2007-01-29
Points: 0

I have a class extending JPanel which I created a simple Line Border (Width 1 and Color.WHITE) with a Color.RED for the component. Using default rendering hints the vertical border lines have an antialias effect. Using KEY_ANTIALIAS_OFF it draws the left/top edges with width 1 but the right/bottom edges with width 2. Using the STROKE_PURE setting seems to have no effect. Testing the line border with a single pixel width on JButton works fine but I cannot distinguish what I'm doing differently. I have attached an image to illustrate the issue. THanks for any assistance.

I know this is something simple I am overlooking.

AttachmentSize
temp.jpg1.94 KB

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ecrouse
Offline
Joined: 2007-01-29
Points: 0

Problem Solved. I had a fairly complex hierarchy of components including a JLayeredPane and several JPanels which were child components of JLayeredPane. That really isn't the issue though. The problem was the Graphics object Stroke characteristic was being set to a stroke width to 2.0f in one of the child panels. So of course when we later on eventually draw the border it uses the same stroke of 2.0f. When setting the stroke characteristic it is ideal to obtain the old stroke and once finished painting with the graphics object reset or revert back to the oldStroke as they instruct you to do in the Java Documentation.