Removing elements from a scroll area

I got a scroll area with lines of items in it. One of those items is a button to delete the item line.

From what I (think I know), you need to add stuff to a scroll area before adding it to a a window if you want it to display it’s new content.

Since I don’t want to go through the hassle of repositioning it’s content, I’m removing the line from the data and refilling the content of the scroll area from the data.
So I remove the scroll area, empty + refill it and add it back, but the buttons don’t react anymore.
I tried removing window, do that and add the window back (to the screen), but didn’t work either.

Is there a refresh window method or scroll area I’m unaware of, or am I simply doing all that badly?
I could rebuild the whole window from scratch, but that brings trouble due to my architecture.

Here is the peace of code I had most hopes with :D:
[java]
ScrollAreaAdapter area = (ScrollAreaAdapter)screen.getElementById(“serversScrollArea”);
window.removeChild(area);
area.removeAllChildren();//needed?
area = createServerListListArea();
fillServerListList(area);
window.addChild(area);
[/java]

Let me check into this and I’ll post specifics on how to handle it. This is related to the same issue I see with ray casting not seeing elements in the proper z-order (i.e. the screen renders properly, but collision results are not returned properly.

My gut reaction is to do this:

Repopulate the scrollarea and then remove the absolute parent from the screen and place it back again. This should fix any issues you are seeing… Buuuut, let me test it to be sure. (Or you can… if you do before I do… post to let me know!)

Thx :).
Not sure if I’m getting the absolute parent thingy right, but I tried:

  • I’ve tried emptying + refilling scroll area and then window.removeChild(area) + window.addChild(area)
  • I’ve tried emptying + refilling scroll area and then screen.removeElement(window) + screen.addElement(window)

Didn’t work :D.

@loopies said: Thx :). Not sure if I'm getting the absolute parent thingy right, but I tried:
  • I’ve tried emptying + refilling scroll area and then window.removeChild(area) + window.addChild(area)
  • I’ve tried emptying + refilling scroll area and then screen.removeElement(window) + screen.addElement(window)

Didn’t work :D.

Yeah… the second thing you mentioned was what I meant =)

Oh… I think I see what the problem is. I missed it the first time I read the original post. The removeAllChildren() call against the scrollarea is likely the problem. Internal to the scrollArea control is a scrollableArea element that contains your elements. By calling removeAllChildren() against the ScrollArea itself, it is likely removing the scroll bar, the scroll content element, etc. The control is probably attempting to reconstruct itself… just not doing it properly :stuck_out_tongue:

EDIT: If you take a look at the Menu class, there is a method called pack() This is a fairly decent example of how to reconstruct the scroll content area when needed. Menu is an extended ScrollArea… so it should contain the basics of what you want to do. The ScrollAreaAdapter (if I remember correctly) should be doing this for you… but the pack() method of Menu is a great reference for managing complex scroll area content.

Ok, got it working. Indeed, the removeAllChildren() call against the scrollarea is harmful here.

You need to:

  • remove the window from the screen
  • remove the scrollarea from the window
  • create a new scrollarea
  • fill the scrollarea
  • add the scrollarea to the window
  • position the window
  • add the window to the screen

[java]
ScrollAreaAdapter area = (ScrollAreaAdapter)screen.getElementById(“serversScrollArea”);
screen.removeElement(window);
window.removeChild(area);
area = displayServerListListArea(); //creates a new scrollArea
fillServerListList(area); //fills the new scrollArea
window.addChild(area);
window.setPosition(new Vector2f(W_WINDOW_DEFAULT_LOCATION_X, V_WINDOW_DEFAULT_LOCATION_Y));
screen.addElement(window);
[/java]