-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.3.0
-
generic
-
generic
Name: rlT66838 Date: 09/29/99
=20
The example program below brings up a panel that
is supposed to have a dashed border. Using JDK1.2.2,
it's drawn as expected (there are four dashed lines
visible). However, using the new JRE1.3beta, only
the lines at the right and bottom sides of the panel
are visible, at the wrong position. This happens because
the rectangle seems to be drawn with an imaginary offset
of (-1,-1). If a BasicStroke with a solid pattern is
used, everything is drawn correctly.
---
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class BasicStrokeBug extends JDialog {
private static class DashedBorder implements Border {
public Insets getBorderInsets(Component c) {
return new Insets(1, 1, 1, 1);
}
=20
public boolean isBorderOpaque() {
return false;
}
=20
public void paintBorder(Component c, Graphics g, int x, int y,
int width, int height) {
Graphics2D g2d =3D (Graphics2D) g;
=20
Color oldCol =3D g2d.getColor();
Stroke oldStr =3D g2d.getStroke();
=20
g2d.setColor(Color.black);
// this works:
// g2d.setStroke(new BasicStroke(1.0f));
// this doesn't:
g2d.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL, 1.0f, new float[] {1.0f, 1.0f}, 0.0f));
=20
g2d.drawRect(x, y, width - 1, height - 1);
=20
g2d.setStroke(oldStr);
g2d.setColor(oldCol);
}
}
=20
public BasicStrokeBug() {
super((Frame) null, "BasicStroke bug", true);
=20
JPanel outerPnl =3D new JPanel();
outerPnl.setBorder(new EmptyBorder(25, 25, 25, 25));
=20
JPanel innerPnl =3D new JPanel();
innerPnl.setPreferredSize(new Dimension(200, 200));
innerPnl.setBorder(new DashedBorder());
innerPnl.setBackground(Color.cyan);
=20
outerPnl.add(innerPnl);
=20
getContentPane().add(outerPnl);
=20
setSize(new Dimension(350, 285));
setVisible(true);
}
=20
public static void main(String args[]) {
new BasicStrokeBug();
System.exit(0);
}
}
(Review ID: 95876)=20
======================================================================
- duplicates
-
JDK-4255392 Drawing a rect with 1.0 pixel width always gets drawn at least 2 pixels wide.
-
- Closed
-