Hi davood,
You may fill the gap by a draw operation that slightly overlaps the inner and
outer area.
[code]
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class AreaTest extends JComponent {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new AreaTest(false), BorderLayout.LINE_START);
frame.add(new AreaTest(true), BorderLayout.LINE_END);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
private final boolean antiAlias;
public AreaTest(boolean antiAlias) {
this.antiAlias = antiAlias;
}
@Override
public Dimension getPreferredSize() {
return new Dimension(270, 270);
}
private void drawTest(Graphics2D g2) {
System.out.println("Drawing " + getBounds());
g2.setColor(Color.WHITE);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON
: RenderingHints.VALUE_ANTIALIAS_OFF);
g2.fillRect(0, 0, getWidth(), getHeight());
Ellipse2D shape1 = new Ellipse2D.Double(50, 85, 150, 60);
Shape shape3 = new Rectangle2D.Double(10, 10, 250, 250);
Area area = new Area(shape3);
area.subtract(new Area(shape1));
g2.setColor(new Color(86 / 256f, 114 / 256f, 142 / 256f, 1f));
g2.fill(area);
g2.setColor(new Color(86 / 256f, 144 / 256f, 182 / 256f, 1f));
g2.fill(shape1);
// fill the white gap by overlapping it
g2.setStroke(new BasicStroke(2f));
g2.draw(shape1);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
drawTest((Graphics2D) g);
}
}
[/code]
Piet
[Message sent by forum member 'pietblok' (pietblok)]
http://forums.java.net/jive/thread.jspa?messageID=316968
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".