Customize the position cordinates of elements, panel and layer!?

hey there,

can i know how to place an element at a customized position in a panel?


place a panel at a customized position in a layer?


place a layer at a customized position in a screen?

using nifty GUI?

Thank You!

What do you mean by “customize”?

Nifty works like CSS/HTML tables. That’s simple.

Then there’s the “absolute” placement of elements. Is that what you’re talking about? Please be precise when asking questions.

yea what i meant was, i wanna put a element at a particular position or at particular co-ordinates on the panel,

so do i have to use absolute for that?

if it is,? i couldnt find any documentation on how to use it, can u link me please :slight_smile:

You have to define the “thing” you want to be set at a certain point on the screen with absolute. For example, let’s say a panel that will contain buttons or whatever.


<panel id=“somePanel” childLayout=“absolute” … >

<panel id=“doesnotMatter” x=“10” y=“20” >

<control name=“button” … stuff=“here” x=“15” y=“25”>

[… etc …]




The above would make a panel with absolute positioning. The first child of that panel (another panel) says where it should be placed and the children of that second panel will be placed according to its location. So in short, that second panel will be placed 10 pixels to the right and 20 pixels lower than the location of the first panel. The tags x="[number]" and y="[number]" do the placement in PIXELS. If x/y tags are used on an element not belonging to a container defined as absolute, they will be ignored. Thus you can place any elements by using x/y tags while inside an absolute positioned container.

That’s pretty much it.

Oh crap. Sorry for the formatting. sigh You’ll have to decipher that. It’s not my fault. :frowning:

Thanks brotha ! :slight_smile:

thanks, it helped me :slight_smile:

I see… Yeah, thanks for this information madjack! :smiley:

I was also wondering, am I missing something in this piece of code if I want to move the panel dynamically? Say, I have already added childLayout=“absolute” in the file as shown below and yes, manually changing x, y position here is working fine.

So, for example, over at the Java side, the code is:


Element timeDisplay, timeDisplayPanel;

//The binding

public void bind(Nifty nifty, Screen screen) {

screenie = screen;

timeDisplay = screen.findElementByName(“timeText”);

timeDisplayPanel = screen.findElementByName(“timePanel”);


// A sample moving panel piece of code from side to side.

// I call this method in the simpleUpdate().

public void movePanel() {

if (i == 300 || i == 19) {

x = x * (-1);


i += x;

value = String.valueOf(i);

timeDisplayPanel.setConstraintX(new SizeValue(value));




…and the xml file.

[xml]<screen id=“start” controller=“TestPack6.PrintTextMovePanel”>

<layer id=“layer” backgroundColor="#0030" childLayout=“absolute”>

<panel id=“timePanel” height=“25%” width=“35%” backgroundColor="#9903" x=“10” y=“20” childLayout=“center” visibleToMouse=“true”>

<text id=“timeText” font=“Interface/Fonts/Verdana.fnt” color="#f03f" text=“milo.” x=“10” y=“20” align=“center” valign=“center” />




Pardon me on the XML code… :confused: the XML tag formatting isn’t working too well for now.

I was wondering if I’m actually typing correctly in the movePanel() method in order to move the panel on its x and y?

Do I need to do some rendering or something related?

Thanks :slight_smile:

EDIT to the previous post:

Sorry, didn’t meant to double post here but I couldn’t get into Edit mode on the previous post.

Anyway, I solved the problem to the post I made just 2 minutes earlier.

The problem lied in this 2 lines in the Java file:


timeDisplayPanel.setConstraintX(new SizeValue(value));



when it should be this instead:


timeDisplayPanel.setConstraintX(new SizeValue(value));



Just wanna share this point in-case someone’s doing this part (or something similar) as well but couldn’t get stuff to be dynamically moving around such as the panel.

I’m guessing what you need to take note here is this if you’re dynamically moving a panel (or a layer?): Depending on who is the parent of that element that has childLayout=“absolute”, though you’re changing the X or/and Y position of the current panel, you will need to re-layout the parent’s element positioning layout again.