0

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)?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
DuskFall
  • 422
  • 2
  • 14
  • 1
    Swap 500 and 700 - the canvas is larger than the window currently. – Njol Jan 14 '14 at 09:43
  • seriously, it was that simple? *facepalm* thank you – DuskFall Jan 14 '14 at 09:46
  • The border decoration insets are likely to be different on different systems, this means that while you might be able to "guess" the size of the viewable area on your system, it will change on the different systems. Better to use an appropriate layout manager, like BorderLayout, that will be capable of responding to these solutions more appropriately. The correct use of getPreferredSize and pack will result in a better result. You should also be careful with mixing heaven and light weight components – MadProgrammer Jan 14 '14 at 10:12

1 Answers1

0

Try this:

canvas.setBounds(0, 0, 500, 600); //instead of 700 for height, your Canvas has height 600