This is probably something obvious I'm missing (yet again) but I can't seem to figure out how to make a jME window resizable – that is, how to allow the user to grab the window's resize gadget and shape it as they wish.
As far as I can see, the choice is either to grab the full screen or to display in a fixed size window. I realize the geometry of the window can be modified programatically but there seems no way to give the user direct control.
I'm using StandardGame if that makes any difference.
Am I missing something somewhere?
I do not think the Native window can be re-sized (at least not without some modification, ie digging into LWJGL if you use that renderer). However, a canvas embedded in say a Swing or SWT application can be re-sized.
To allow a user direct control, you can always have a pop-up settings window before the native window is created (heck, even AAA games like Fallout 3 do this, you can only change graphical settings in the launcher menu).
Of course that's assuming you're working on a game!
Starnick said:
However, a canvas embedded in say a Swing or SWT application can be re-sized.
That occurred to me but I couldn't find anywhere in the documentation how to do that. I've probably missed something somewhere but if someone could give me a pointer or even a gentle nudge in the right direction, I'd appreciate it. I searched around for example code but came up empty handed.
Starnick said:
Of course that's assuming you're working on a game!
As I mentioned elsewhere, no, I'm not working on a game, though I'm not sure how that would affect a solution, one way or another.
Swing-Frames should be resizeable by default.
Here is the Sun-Tutorial for a Main Frame with Swing:
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html
Here is the function do enable/disable the resize-ability of an AWT-/Swing-Frame:
http://java.sun.com/javase/6/docs/api/java/awt/Frame.html#setResizable(boolean)
The jME-DisplaySystem has the function "createCanvas(int w, int h);" Starnick talked about.
This function creates an AWT-Canvas:
http://java.sun.com/javase/6/docs/api/java/awt/Canvas.html
This can be resized with the setSize(int,int)-function:
http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setSize(int, int)
Thanks. I am, of course, aware of how to create a window, etc.
It was the actual mechanics of telling StandardGame how to create itself in a Canvas that were not clear. Looking at the source code, it appears that one sets the DISPLAY_MODE field but this is not documented. I'll have to experiment further with this, I suppose.
FOLLOWUP: I attempted to create StandardGame with a Canvas by setting
StandardGame.DISPLAY_MODE = StandardGame.DISPLAY_CANVAS;
StandardGame sg = new StandardGame( "Test", StandardGame.GameType.GRAPHICAL );
and got a NullPointerException as a reward for my efforts.
The traceback follows:
java.lang.NullPointerException
at com.jmex.game.StandardGame.initSystem(StandardGame.java:326)
at com.jmex.game.StandardGame.run(StandardGamex.java:229)
at java.lang.Thread.run(Thread.java:619)
The offending line of code is
camera = display.getRenderer().createCamera(display.getWidth(), display.getHeight());
It would appear that a Renderer is not being created by
canvas = (Canvas)display.createCanvas(settings.getWidth(), settings.getHeight());
At this point, I'm not sure what to do.
My examples were that of professionally made games, it's just an example for how to configure a game I guess, since a lot of jme apps are games afterall. It probably won't affect the solution.
I can't comment on standard game, since I've never used it. However, generally the easiest way to use jme in a swing frame is to use the JMECanvasImplementor class.
Notable examples that use that class would be the two editors in the test packages, RenParticleEditor and that camera editor one.
Actually I think the easiest way to implement canvas would be to use Display.setParent(java.awt.Canvas canvas) like the new Applets use. Check out SimpleApplet or StandardApplet and the initForApplet in LWJGLRenderer.