Nifty: Switching Panels and nonworking aligment

Ok I have a screen and in this screen there are multiple panels defined, they all have the visible false property. Then there are some buttons each has effects associated, namely onClick hide and show for the panels. It works partially, because the panels disappear and appear as intended. The problem is, that the positioning is not working; it is like all the invisible panels are still there and taking up space. Is it possible to get this working this way or do I have to do it from code?

Furthermore, Labels don’t seem to respond to the align property, if I give them the align=”left” property the text is still displayed centered.

Nifty as a whole seems rather confusing… Should one use the thingy or the eventbus… How much behavior should be in the xml how much in the controller class?

I honestly didn’t exactly get what the problem is in the first paragraph. Is the problem the panels that seem out of alignment? Is it the buttons that don’t (sometimes?) disappear/appear?

I think I may understand but don’t want to write a long post if it’s about the wrong thing… When you write an XML file constructing the “screen”, all elements are static. Meaning, they can’t be moved around. That is, unless you use childLayout=“absolute”.

As for labels and alignment, align and valign affect CONTROLS only and those tags are for children elements, not text. It’s like saying: in this panel, all children elements will be align=“right” or whereever you want them to be. If you want to align text inside a control, you use textVAlign or textHAlign followed by = then one of following: center, left, right, top, bottom depending on which tag it is.

I hope it’s clearer.

Nifty is very powerful but it has a learning curve.

Ill try to explain the first part of my problem:

I have a screen, in there i have deifned multiple panels all except the first have the property visible=“false” set.

In the first panel that is always visible I have some buttons.

Each of those has an effect associated that shows one of the hidden panels and hides the others.

Something like this:



<onClick name=“show” targetElement=“editPanel” />

<onClick name=“hide” targetElement=“optionsPanel” />



This works in a way… The problem is, that the LAyout seems to palce the hidden panels too. So for example if I hide the first panel and show the second. Its placed below the empty space where the first hidden panel would be.

I hope this makes my prolbem a bit clearer


[java]element.layoutElements() [/java]

(on a parent element) after having done your changes. Then they should look proper.

You can also do:


to refresh the whole screen.


What you don’t seem to understand is that even if the screen elements are hidden, they still exist and at their proper places in the screen.

Look at a XML screen definition as a web page with one static table if you want. As long as you don’t use absolute placement on the container (or cells in the table example), they WILL RETAIN their place on the screen. That they are visible or not is unimportant.

The only way to have panels or layers or any element at a certain position on the screen is to use childLayout=“absolute” on the container of the element. Then, you place each element with x="# pixel from left" y="# of pixels from top".

If you don’t use the above, each panel will be placed in the order they are declared in the screen XML.

Hopefully that’s clearer. :slight_smile:

Thank you! Yes that was the problem I am doing it from code now , this way it almost does what i want…

I have a new problem now:

I want the onHide effect of the panel to play before it is removed. I tried using:





this removes the panel , but doesnt wait for the onHide effect to play.

How can i remove the element only after the effect is done?

check the Nifty version you are using, if you have this method at the element class:

[java]public void hide(final EndNotify perform) {[/java]

you can use the EndNotify interface so that Nifty can call you back, when the hide effect has ended.

back to your initial problem:

@madjack explained it very well! thanks a lot! :smiley: to summarize: “invisible / hidden elements are still a part of the layout process and still take up space”.

removing them - what it seems like you’re doing now - is the correct way when you need them to be removed from the layout process.