Resizing JME Window

Hey guys, everytime I connect to an projector my jme window becomes messed up and then I have to change the resolution of the screen and adjust it properly. I am trying to be able to resize the JME window on the fly. I have seen other posts suggesting using: TestRecreateWindow. to do so however that code is old and deprecated.

Anyone could point me to what are the steps I need to use or a working example of a resizable JME window?

I ve also read : https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:swing_canvas and not sure if that’s one way to go as I couldn’t get the example to run.

thanks

these are the settings I am currently using:

[java] // initialize internal settings
AppSettings defaultSetting = new AppSettings(true);

    // set window title
    defaultSetting.setTitle("TESTING WINDOW");

    // set window height and width
    defaultSetting.setHeight(950);
    defaultSetting.setWidth(1600);

    // Vsynch - Set vertical synching to true to time the frame buffer
    // to coincide with the refresh frequency of the screen.
    // VSync prevents ugly page tearing artifacts, but is a bit slower.
    defaultSetting.setVSync(false);
    defaultSetting.setFrequency(60);

    // take off settings after putting them into effect
    setShowSettings(false);
    setSettings(defaultSetting);

[/java]

Try to change the settings and call app.restart() where app is the SimpleApplication to update the context.

Not sure we’re on the same page or I quite understood u. I am trying to be able to select the sides of the JME window and resize just like it’s possible to do with any JFrame window

@jonesadev I did what you said and created a temporary method that is called toggleToProjector() where I pass new settings and restart - THANKS! but this is more of a hack. I am looking for a real solution which allows me to resize the JME window on the fly

You can also create a canvas and display it in a JFrame.

I made a test case for you :

[java]public class Main extends SimpleApplication
{

public static void main(String[] args)
{
    Main app = new Main();
    
    Frame _frame = new JFrame();
    _frame.setLocationRelativeTo(null);
    _frame.setVisible(true);
    
    AppSettings settings = new AppSettings(true);
    settings.setWidth(1280);
    settings.setHeight(720);
    settings.setUseInput(false);
    app.setSettings(settings);
    
    _frame.setPreferredSize(new Dimension(settings.getWidth(), settings.getHeight()));
    _frame.setResizable(true);
    
    app.createCanvas();
    
    JmeCanvasContext _canvasCtx = (JmeCanvasContext) app.getContext();
    _canvasCtx.setSystemListener(app);
    Canvas _canvas = _canvasCtx.getCanvas();
    _canvas.setPreferredSize(new Dimension(settings.getWidth(), settings.getHeight()));

    _frame.add(_canvas);
    _frame.pack();
    
    app.startCanvas();
}

@Override
public void simpleInitApp()
{
    
}

@Override
public void simpleUpdate(float tpf)
{
    
}

@Override
public void simpleRender(RenderManager rm)
{
    
}

}[/java]

1 Like