0

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:

https://i.stack.imgur.com/3q3KV.png

G RB
  • 1
  • 1
  • 2
    I only see a single pixel. I am using scaling at 100%. Is it maybe because you are using Windows scaling and some pixels are scaled while other are not? Post a proper [mre] for other to test. – camickr Jun 09 '21 at 22:44
  • One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). E.G. The code in [this answer](https://stackoverflow.com/a/10862262/418556) hot links to an image embedded in [this question](https://stackoverflow.com/q/10861852/418556). – Andrew Thompson Jun 10 '21 at 08:41
  • "Minimal reproducible example" added to the code in the original post. – G RB Jun 11 '21 at 15:55
  • I don't see [the effect](https://i.stack.imgur.com/4ZqHS.png) here. – Andrew Thompson Jun 11 '21 at 18:14
  • Like camickr said, it was the windows scaling, I didn't even know that existed. Thanks a lot everyone. – G RB Jun 14 '21 at 22:24

0 Answers0