Question

So i've got a java JFrame which i'm putting a canvas in, and its appearing at the wrong coordinates, as if its taking 0,0 as the bottom left corner, rather than top left. Here's my code.

    JFrame frame = new JFrame("Test");
    frame.setSize(800,600);
    frame.setLayout(null);
    frame.setResizable(false);

    final Canvas canvas = new Canvas();
    canvas.setBounds(0, 0, 500, 700);
    canvas.setFocusable(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(null);
    frame.add(canvas);

    frame.setVisible(true);

Why isnt it using conventional window coordinates (As in 0,0 being the top left corner)?

Was it helpful?

Solution

Try this:

canvas.setBounds(0, 0, 500, 600); //instead of 700 for height, your Canvas has height 600
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top