I drew three dots on a JPanel using fillRect method from Graphics, but for some reason the third dot is wider than the other two, this seems to happend every three "pixels" or so, which is giving me problems when implementing the DDA line algorithm. I also tried to use setRGB from a BufferedImage to draw the pixels, I got the same result. I also tried to use a pixel array extracted from the BufferedImage data, I got the same result. Any thoughts? Thanks in advance.
This is the code on the JPanel's paintComponent method:
public class Lineas extends JPanel{
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
g.fillRect(1, 1, 1, 1);
g.setColor(Color.green);
g.fillRect(2, 2, 1, 1);
g.setColor(Color.blue);
g.fillRect(3, 3, 1, 1);
}
public static void main(String args[]) {
JFrame ventana = new JFrame("Líneas");
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.setSize(600, 600);
ventana.add(new Lineas());
ventana.setVisible(true);
}
}
This is the result on the JPanel: