I'm using Swing's GeneralPath to create complex shapes and fill them. Usually I do this, and it creates a nice hexagon for me:

path.moveTo(100, 100);
		path.lineTo(150, 100);
		path.lineTo(180, 150);
		path.lineTo(150, 200);
		path.lineTo(100, 200);
		path.lineTo(70, 150);
		path.lineTo(100, 100);
		g2.draw(path);

Suppose I wanted to create a donut-shaped GeneralPath, and do this:

path.moveTo(100, 100);
		path.lineTo(150, 100);
		path.lineTo(180, 150);
		path.lineTo(150, 200);
		path.lineTo(100, 200);
		path.lineTo(70, 150);
		path.lineTo(100, 100);
		path.moveTo(110, 110);
		path.lineTo(125, 120);
		path.lineTo(110, 120);
		path.lineTo(110, 110);
		path.closePath();

Draw this and you'll get the same hexagon with a closed triangle in the middle (a pretty bad donut, yeah).
That's all fine, but when I try to fill it using g.fill(), it fills the middle triangle portion too - so instead of the middle of the donut being white, it's filled in and I see just a hexagon.

Here's the full code so you can try it yourself:

public class GeneralPath1 extends Applet
{
	private GeneralPath path;
	
	public GeneralPath1()
	{
		path = new GeneralPath();
		
		path.moveTo(100, 100);
		path.lineTo(150, 100);
		path.lineTo(180, 150);
		path.lineTo(150, 200);
		path.lineTo(100, 200);
		path.lineTo(70, 150);
		path.lineTo(100, 100);
		path.moveTo(110, 110);
		path.lineTo(125, 120);
		path.lineTo(110, 120);
		path.lineTo(110, 110);
		path.closePath();
	}

	public void paint(Graphics gr)
	{
		setSize(600, 600);
		Graphics2D g2 = (Graphics2D) gr;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		
		path.closePath();
		//g2.draw(path);
		g2.fill(path);
		g2.setPaint(Color.black);			
	}
}

Maybe you can do that then fill the inner triangle with a transparent color (alpha = 0)?
OR
Maybe you can convert that shape into a single line so swing can understand inside/outside properly? - ie path round the outside, path a connecting line to the inner shape, path the inner shape then connect back to the outside shape back along the same line that you connected in with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.