Nifty - usage of two scrollpanelbuilders (Solved)

Hi,

I am trying to implement two different scroll panels, but I having problems to find the right scrollpanel ID. Usually the id is “#nifty-scrollpanel-child-root”, but I seems to not working if I have two different scroll panels. Is there any way to use two unique ids for the scroll panels?

I’m not exactly sure what you are trying to do. You can pass an ID to a scrollpanel when you build it… Usually you create a child panel yourself that contains the information in the scroll panel if that is what you are trying to get access to.

If you look at the wiki on github it gives the example of:

<control id="scrollbarPanelId" name="scrollPanel" horizontal="false" height="225px">
   <panel id="myScrollStuff" width="370px" childLayout="vertical" />
</control>

You have the panel itself which is “scrollbarPanelId” and the child element that you add items to “myScrollStuff”.

In xml it’s pretty easy, but using builders is a different case.

An example:
ScollpanelBuilder:

parentElement = element;
createScrollPanel = new ScrollPanelBuilder("Test-Content1");
createScrollPanel.width("*");
createScrollPanel.height("*");
createScrollPanel.style("");
createScrollPanel.set("horizontal", "false");
createScrollPanel.focusable(false);
createScrollPanel.set("vertical", "true");
createScrollPanel.build(nifty, screen, parentElement);

ScrollContentPanel:

parentElement = checkParentID("#nifty-scrollpanel-child-root");
createPanel = new PanelCreator();
createPanel.setId(windowName + "-Content" + idCountContent);
createPanel.setHeight("500px");
createPanel.setWidth("100%");
createPanel.setChildLayout(childLayout);
createPanel.create(nifty, screen, parentElement);

Is there maybe an unique id regarding “#nifty-scrollpanel-child-root”?

I’m not familiar with Java nifty but you could maybe try:

createScrollPanel.set("id", "yourID");

Not working, also because the element id is already set. Somehow the scrollpanelbuilder generates a separate content id.

Its the same in java as xml.

control(new ScrollPanelBuilder("scrollbarPanelId") {{
  width("*");
  height("*");
  panel(new PanelBuilder("myScrollStuff") {{
    ...
  }});
}});

I will give a try. Regarding the id, one answer was the following:

Yes, in the case of scroll panels nifty does some extra stuff and counts on their being one “child” container, however, you can add multiple children to “myScrollStuff” above as long as you set the size of the “myScrollStuff” element correctly.

In the above example “myScrollStuff” is child to #nifty-scrollpanel-child-root.

Now that you’ve expanded a little bit I think your problem is that you are attempting to grab the #nifty-scrollpanel-child-root but you are doing it from a parent element that contains both scroll panels. What you need to do is find the scroll panel element first and then find the #nifty-scrollpanel-child-root for THAT element. Otherwise, once you add 2 scroll panels there are two #nifty-scrollpanel-child-root.

But how do I know which element belongs to which scroll panel? Right after I created the first scroll panel element, I create the scroll panel which will hold all content. I am doing the same with the second scroll panel element.

Well since you don’t have your code posted here I don’t know what to tell you. When you call “build” it returns the newly created element which you can track in your code so I don’t know what you are missing here without seeing what the actual problem is in your code.

This could be a bit complicate to show my code, also because of it’s structure. :confused: Is there any way to change the id of “#nifty-scrollpanel-child-root”? Something like .set(rootID, newID)?

Update: Found the solution: “#nifty-scrollpanel-child-root” is attached to the element id of the scroll panel builder which means the root element is scrollpanelbuilderID + “#nifty-scrollpanel-child-root” and not only “#nifty-scrollpanel-child-root” (that’s a pretty big difference for me).