-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
sparc
-
solaris_7
Name: dbT83986 Date: 05/14/99
I am using two rectangle shapes to create an arc:
The outer rectangle (yellow) defines the ellipse that contains
the arc (red), and the inner rectangle (yellow) defines the clip
in the graphics context that contains the arc.
With the viewport position at (0,0) the code behaves as expected.
But after scrolling to a different position, the clip
misbehaves!
Sample code follows:
/*
* This code is based on an example from the java tutorial:
* tutorial/uiswing/components/example-swing/ScrollDemo2.java
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class ClipBug extends JPanel {
JPanel drawingArea;
public ClipBug() {
super();
setOpaque(true);
//Set up the drawing area
drawingArea = new JPanel() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Using two rectangles to create an arc:
// r1 defines the ellipse that contains the
// arc
// r2 is the clip or bounding box that contains
// the arc
// With the view position at (0,0), this code
// behaves as expected, but after scrolling to
// a different view position, the clip frame
// seems to behave a bit silly :(
Rectangle2D.Double r1 = new Rectangle2D.Double(100, 100, 100, 100);
Rectangle2D.Double r2 = new Rectangle2D.Double(110, 100, 80, 40);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.yellow);
g2.draw(r1);
g2.draw(r2);
Shape clip = g2.getClip();
g2.setClip(r2);
g2.setColor(Color.red);
g2.draw(new Ellipse2D.Double(100, 100, 100, 100));
g2.setClip(clip);
}
};
drawingArea.setBackground(Color.black);
drawingArea.setPreferredSize(new Dimension(600,600));
//Put the drawing area in a scroll pane
JScrollPane scroller = new JScrollPane(drawingArea);
scroller.setPreferredSize(new Dimension(300,300));
//Layout this demo
setLayout(new BorderLayout());
add(scroller, BorderLayout.CENTER);
}
public static void main (String args[]) {
JFrame frame = new JFrame("Clip Bug");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
frame.setContentPane(new ClipBug());
frame.pack();
frame.setVisible(true);
}
}
(Review ID: 55734)
======================================================================
- duplicates
-
JDK-4220924 Clipping in translated Image Graphics isn't correct
-
- Resolved
-