Size of Window (not canvas)

Hello,

if I run a jme application in windowed mode, is there the possibility to obtain the size of the window (not the canvas)? I Would like to resize the window based on the window size and not on the canvas size.

Your help is appreciated, thank you.

Michael

You can use swing to query the window settings, the insets of the frame give you all the borders etc.

I’ve sometimes found it isn’t 100% accurate but it gets pretty close.

Thanks, but my problem ist that I do not know how to get access to the window frame. I am searching for the pointer to the window which is finally created by LWJGL…

Thank you.

Michael

I’m guessing you mean screen size i.e., 600x800, 1280x800, etc?

I use this.settings.getWidth(); and this.settings.getHeight(); Hope this helps!

You can use a Canvas inside a standard Swing JFrame, then you have all the data that you need.
Somebody posted model code for that recently, search the forum for JFrame. (I have my own implementation, but it was vastly more complicated and showed glitches.)

Canvas basic implementation is available > Here <

Using swing might lead to some performance drawbacks. If you’re using LWJGL Display, you can simply call Display.setResizable(true); and the window will become resizable, however, the viewport wont resize to it’s new size… most probably smth to do with the jme3’s LWJGL Thread. To do that you need to add this in ur update or render loop.

2 Likes

Ah, thanks, I’ve been thinking that a Display can’t be made resizable because I’ve been overlooking that setResizable call.
Not sure about the performance issues with Swing. Swing was once slow, but nowadays Eclipse’s GUI performance is worst across the board of Java applications, and that’s written in SWT… in other words, I think it’s more what you do inside the GUI, rather than the GUI itself, that can cause performance issues. That said, it’s always possible to do something wrong if you use a complicated framework, and Swing and SWT and AWT and you-name-it are all complicated, so it’s generally better to stick with the standard Display if you don’t need to adorn your OpenGL window with menus and buttons and whatnot.

UPDATE. That worked BEAUTIFULLY. Many thanks.

Here’s some model code, with the stereotypical blue box in the middle:
[java]package org.toolforger.com.jme3.app;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.JmeContext;
import org.lwjgl.opengl.Display;

/**

  • An Application that has a single, resizable main window.

  • This particular incarnation shows just a blue box.
    */
    public class WindowedApplication extends SimpleApplication {

    public static void main(String[] args) {
    WindowedApplication app = new WindowedApplication();
    app.start(JmeContext.Type.Display); // start the game
    }

    @Override
    public void simpleInitApp() {
    // Make the main window resizable
    Display.setResizable(true);
    // Prevent the flycam from grabbing the mouse
    // This is necessary because otherwise we couldn’t resize the window.
    flyCam.setDragToRotate(true);
    // Create that blue box.
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry(“Box”, b);
    Material mat = new Material(assetManager,
    “Common/MatDefs/Misc/Unshaded.j3md”);
    mat.setColor(“Color”, ColorRGBA.Blue);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
    }

    @Override
    public void update() {
    super.update();
    if (Display.wasResized()) {
    int newWidth = Math.max(Display.getWidth(), 1);
    int newHeight = Math.max(Display.getHeight(), 1);
    reshape(newWidth, newHeight);
    }
    }

}[/java]

1 Like

Hello

thanks a lot for your answers, they really helped. My application was in a awt/swing canvas, but i get better performance in an LWJGL-canvas. I cannot switch to fullscreen know since I have a lot of Java/Swing-configuration windows. Thus I have to stick to the LWJGL-Display.

Dispplay.setResizable(true); works pretty well and I added the Display.wasResized() thing in the render thread. To avaoid the new resized window to automaticappy moved to the center of the screen, I store the positions after resize: Display.getX() … and set them after the restart with Display.setLocation(…

This seems to work pretty well, at least on Windows. I’ll test this on Mac OS-X and Linux, too.

Thanks again for the fruitful discussion!

MIchael