AWT Frame and Canvas parented to LWJGL Display is resizing on creation

This is baffling me. For some reason, the AWT Frame and its child canvas that I’m using with LWJGL’s Display.setParent() is resizing itself away from the dimensions I set it as. This used to work fine, and looking through my revision history, I can’t figure out how I broke it.

Relevant parts of my code:


//Frame f is a static final that is initialized when it is declared.

setupFrame(Canvas c) {
        //determine the width and height to use for the game window, put them in resX, resY
        f.setSize(resX, resY);
        f.setResizable(false);
        f.setIgnoreRepaint(true);
        f.add(c);
        f.setVisible(true);
}

setupLWJGL() {
        //locate natives, then...
        try {
            Display.setDisplayMode(new DisplayMode(resX, resY));
            Display.setParent(cnv); //cnv is the same as c from the setupFrame(Canvas c)
            Display.create();
        } catch(LWJGLException ex) {
            Logger.getLogger(GameBase.class.getName()).log(Level.SEVERE, null, ex);
        }
        cnvW = Display.getWidth();
        cnvH = Display.getHeight();
        //...lighting, blending, matrices, etc....
}

Currently, the size of the frame should be 1200x675, and the canvas and Display should be a little less than that (1194x647) because of window borders. However, at some point in the code, the frame and canvas (and thus Display) sizes change from about 1194x647 to 1280x1002.

I’ve been mucking around in NetBean’s debug mode and also with a bunch of print statements to figure out where the canvas and frame end up changing their dimensions. This goes wrong in two different ways and seems to happen at two different spots:

  1. Display.setDisplayMode(new DisplayMode(resX, resY)); Before that line, the canvas dimensions are 1194x647, afterward they are 1280x1002. The game renders correctly, but in a window that takes up the whole screen instead of 1200x675.

  2. f.setVisible(true); The same dimension change occurs during that line. I tried to follow the source code, and it seems to happen when the Component calls peer.setVisible(true).

Sometimes, the window takes up the full screen (it is still a decorated window, it’s not in full screen mode), but only draws on a section of it that looks like it’s about the 1200x675 size the window is supposed to be. I can’t reliably reproduce this, but it happens sometimes. Also, which spot the frame and canvas change dimensions at is unpredictable, but seems to happen more on f.setVisible() when I’m in debug mode.

I’m guessing this isn’t actually due to something within the code I’m using so much as maybe a synchronization issue? Since it seems to change when it happens when I’m using debug mode, the timing seems important.

Any ideas?

EDIT: It looks like if I remove the Display.setDisplayMode(), which I think is supposed to be unnecessary anyway if I give the Display a parent, the resizing changes to during the Display.create() line, and I get the glitch where the window is still big, but the rendering is the right size and takes up only part of the window and is scaled oddly. No, wait… I just ran it again without setDisplayMode(), and it resized at Display.setParent(cnv) and rendered in the whole window. So, this is very inconsistent and seems to not be connected to any particular piece of code I’m writing.