Hi, I'm trying to draw 2 quadrilatrials, that share 2 corners and an egde.

I also want to smooth edges, so I use ANTIALIASING turned on, but this has the effect of showing a crack between the polygons.
The crack dissapears if I turn off ANTIALISAING, but I really don't want to do that.
Is there any way around this (without moving the corner points a pixel or two to hide the gap) ??

Code is shown below:

Class Main

1. import javax.swing.JFrame;  
   2.   
   3. public class Main extends JFrame  
   4. {  
   5.     public Drawer drawer;  
   6.       
   7.   
   8.     public Main()  
   9.     {  
  10.         drawer = new Drawer();  
  11.         this.getContentPane().add(drawer);  
  12.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  13.         this.setResizable(false);  
  14.         this.pack();  
  15.         this.setVisible(true);  
  16.     }  
  17.   
  18.   
  19.     public static void main(String[] args)  
  20.     {  
  21.         new Main();  
  22.     }  
  23. }

Class Drawer

1. import java.awt.Color;  
   2. import java.awt.Dimension;  
   3. import java.awt.Graphics;  
   4. import java.awt.Graphics2D;  
   5. import java.awt.Point;  
   6. import java.awt.RenderingHints;  
   7. import javax.swing.JPanel;  
   8.   
   9.   
  10.   
  11. public class Drawer extends JPanel  
  12. {  
  13.     Point point1 = new Point(100,100);  
  14.     Point point2 = new Point(120,400);  
  15.     Point point3 = new Point(300,100);  
  16.     Point point4 = new Point(320,400);  
  17.     Point point5 = new Point(400,100);  
  18.     Point point6 = new Point(420,400);  
  19.       
  20.     public Drawer()  
  21.     {  
  22.         this.setPreferredSize(new Dimension(500,500));  
  23.         this.setBackground(Color.BLUE);  
  24.     }  
  25.       
  26.     public void paintComponent(Graphics g)  
  27.     {  
  28.         super.paintComponent(g);  
  29.         Graphics2D g2 = (Graphics2D)g;  
  30.         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  
  31.                             RenderingHints.VALUE_ANTIALIAS_ON);  
  32.           
  33.         //g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,  
  34.         //                    RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);  
  35.           
  36.         //g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,  
  37.                //        RenderingHints.VALUE_COLOR_RENDER_QUALITY);  
  38.           
  39.         //g2.setRenderingHint(RenderingHints.KEY_DITHERING,  
  40.                 //        RenderingHints.VALUE_DITHER_ENABLE);  
  41.           
  42.         //g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,  
  43.                 //        RenderingHints.VALUE_FRACTIONALMETRICS_ON);  
  44.           
  45.         //g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,  
  46.                 //  RenderingHints.VALUE_INTERPOLATION_BICUBIC);  
  47.           
  48.         //g2.setRenderingHint(RenderingHints.KEY_RENDERING,  
  49.                 // RenderingHints.VALUE_RENDER_QUALITY);  
  50.           
  51.         //g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,  
  52.                //   RenderingHints.VALUE_STROKE_NORMALIZE);  
  53.           
  54.         g2.setColor(Color.yellow);  
  55.         g2.fillPolygon(new int[]{point1.x, point2.x, point4.x, point3.x},  
  56.                        new int[]{point1.y, point2.y, point4.y, point3.y}, 4);  
  57.           
  58.         g2.fillPolygon(new int[]{point3.x, point4.x, point6.x, point5.x},  
  59.                        new int[]{point3.y, point4.y, point6.y, point5.y}, 4);  
  60.     }  
  61. }

> Is there any way around this (without moving the corner points a pixel or two to hide the gap) ??
Not that I am aware of, short of declaring a general path that describes the outline of both polygons as a single entity.

I see your point, but I need the polygons to be different colours (they will form the basis of 3D models), so I don't think that will work.

I've already built the models... http://colin-java.co.uk/jchess_3_3d.html
But I did it by extending the corners out by a pixel. It works ok, but its not perfect, and I wanted to do it by not messing with the coordinates of the corners

[sorry, reply deleted - would not have worked with different colored areas]

Edited 6 Years Ago by Ezzaral: n/a

This article has been dead for over six months. Start a new discussion instead.