Setting a NiftyGUI panels X and Y location while the game is running in java

I have a panel created in nifty xml and i would just set its Y and X but then if someone plays my game on another screen sized PC the panel wont be where it belongs. So todo so i got the screen size in java and i have worked out the X and Y location that the panel should be set to, i just dont know how to set it in java code,

This is my panel’s XML (i set x and y to 0 because i change it later during the game):
<panel id=“skillBarBottom” backgroundColor="#c3c3c3" width=“355px” height=“46px” x=“0px” y=“0px” childLayout=“absolute”>
<panel id=“skillOneOutline” backgroundColor="#000000" width=“42px” height=“42px” x=“2px” y=“2px” childLayout=“absolute”>
<panel id=“skillOne” backgroundColor="#9b9b9b" width=“40px” height=“40px” x=“1px” y=“1px” childLayout=“absolute”/>
</panel>
<panel id=“skillTwoOutline” backgroundColor="#000000" width=“42px” height=“42px” x=“47px” y=“2px” childLayout=“absolute”>
<panel id=“skillTwo” backgroundColor="#9b9b9b" width=“40px” height=“40px” x=“1px” y=“1px” childLayout=“absolute”/>
</panel>
<panel id=“skillThreeOutline” backgroundColor="#000000" width=“42px” height=“42px” x=“91px” y=“2px” childLayout=“absolute”>
<panel id=“skillThree” backgroundColor="#9b9b9b" width=“40px” height=“40px” x=“1px” y=“1px” childLayout=“absolute”/>
</panel>
<panel id=“skillFourOutline” backgroundColor="#000000" width=“42px” height=“42px” x=“135px” y=“2px” childLayout=“absolute”>
<panel id=“skillFour” backgroundColor="#9b9b9b" width=“40px” height=“40px” x=“1px” y=“1px” childLayout=“absolute”/>
</panel>
<panel id=“skillFiveOutline” backgroundColor="#000000" width=“42px” height=“42px” x=“179px” y=“2px” childLayout=“absolute”>
<panel id=“skillFive” backgroundColor="#9b9b9b" width=“40px” height=“40px” x=“1px” y=“1px” childLayout=“absolute”/>
</panel>
<panel id=“skillSixOutline” backgroundColor="#000000" width=“42px” height=“42px” x=“223px” y=“2px” childLayout=“absolute”>
<panel id=“skillSix” backgroundColor="#9b9b9b" width=“40px” height=“40px” x=“1px” y=“1px” childLayout=“absolute”/>
</panel>
<panel id=“skillSevenOutline” backgroundColor="#000000" width=“42px” height=“42px” x=“267px” y=“2px” childLayout=“absolute”>
<panel id=“skillSeven” backgroundColor="#9b9b9b" width=“40px” height=“40px” x=“1px” y=“1px” childLayout=“absolute”/>
</panel>
<panel id=“skillEightOutline” backgroundColor="#000000" width=“42px” height=“42px” x=“311px” y=“2px” childLayout=“absolute”>
<panel id=“skillEight” backgroundColor="#9b9b9b" width=“40px” height=“40px” x=“1px” y=“1px” childLayout=“absolute”/>
</panel>

And this is my Java code to set its X and Y location but when i do this it doesnt visually change its location:
SizeValue skillX = SizeValue.px(screensize - skillBarSize / 2);
nifty.getCurrentScreen().findElementByName(“skillBarBottom”).setConstraintX(skillX);

Any ideas to make the niftyGUI re-render or update the panels visual location while the game is running ?

You probably need to call layoutElements() method in the parent of your panel :slight_smile:

1 Like
@relucri said: You probably need to call layoutElements() method in the parent of your panel :)

THANKYOU SO MUCH, IVE BEEN STUCK ON THAT FOR 2 WEEKS NOW