[SOLVED] Nifty screen size goes wrong on start (Swing/Application)

Hello guys :}

Even more problems with my program and a new newbie question :confused:
Recently I started with Nifty.

My application runs in a swing frame, but i need some button events on the JME canvas.
So I started with the nifty tutorials and tried o put the example one my JME canvas.
Shown in: [nifty gui xml layout][1]

The problem I have is, that the screen is shown, but the size don’t correlated with the JME canvas.
Only after changing the window size, the size of my nifty screen is displayed correctly.

Is this because im using the JME canvas embedded in Swing frame?
Do I have something special to do?

Here my code part where I do this stuff:
First I exended my application with ScreenController (interface)
Than I do the nifty stuff in the simpleInitApp()

after this I create the methods wich are necessary for the ScreenController Interface

This method returns the JmeCanvasContext:

And finally the main method: create an instance of JFrame and the JME App and put it together

Last but not least here the corresponding xml file for the screen.

Maybe one of you knows what’s wrong here.

A nice evening to all of you and happy programming :blush:

[1]: http://%20http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:nifty_gui_xml_layout

Hi! I have the same problem. Do you have already solved it?

After resizing:

Hi @ipcorp

I’m pitty that I have no solution for you. In my case it was a strange relationship between Nifty, JME and the swing frame. I played arround with different panels where I add my JME canvas. At the one time the error was disappeard and at the other time it cames back :confused:

At the current time I don’t use Nifty and and have been searching for a solution shifted backwards.

If you find something I should be very glad if you could post it here. I will write you too if I find something. :}

nice greets
EsKay :}

@EsKay, I found … it seems :sunglasses:


// 1.Canvas
Canvas cv = ((JmeCanvasContext) getContext()).getCanvas();
cv.setPreferredSize(new Dimension(800, 600));

// 2.Frame
JFrame jf = new JFrame();
// !Window to the center.

// 3. A task object
enqueue(new Callable<Object>() {
    public Object call() throws Exception {
       // The size of my window 800/600, but it can be any value.
       reshape(800, 600);
       return null;

because jme rendering in a separate thread, perhaps therefore occur:

WBR :chimpanzee_smile:

1 Like

Hey its long time ago :3 Had now some time to test your stuff :smiley:
This works fine for me too :slight_smile: Thanks for this smart solution of my nifty problem :blush: