javalwjglslick2dnifty-gui

NiftyGui - how to change size of panel


Is it possible to change size of panel in NiftyGui while the application is running? I tried this code : //init

 mainScreen = new ScreenBuilder("main") {{
     controller(sc);
     layer(new LayerBuilder("foreground"){{
         childLayoutCenter();
         panel(new PanelBuilder("p1"){{
             childLayoutAbsoluteInside();
             backgroundColor("#00ff00");
             width("100%");
             height("100%");
             padding("10px");
             panel(new PanelBuilder("p4"){{
                 x("100%");y("100%");
                 height("20%");
                 width("20%");
                 backgroundColor("#0000ff");
             }});
         }});
     }});
   }}.build(nifty);

//update()

Element f = nifty.getCurrentScreen().findElementById("p4");
f.getParent().layoutElements();
f.setHeight(f.getHeight() + 300);

and nothing is changing.


Solution

  • Ok, I solved this. I was using wrong method. Solution was to use setConstraintHeight(SizeValue) instead of setHeight(int)

    `Element f = nifty.getCurrentScreen().findElementById("p4");
    f.getParent().layoutElements();
    f.setConstraintHeight(new SizeValue(f.getHeight() + 5 + "px"));`