2

I have a figure with a ToolBar Layout. I have added a Label in it(Draw 2D).

I have to add another figure in it dynamically. But when I do add it, the Label moves down and the newly added figure comes at the top.

I have tried adding the label by add(IFigure, index) method, with 0 index but no use!

I noticed the getChilden() list has my label at the bottom. I can keep re-ordering the list, but I don't think its a good idea.

What can I do so that the newly added figures are always at the bottom?

I can't use any other layout than Toolbar layout.

nullpointer
  • 490
  • 2
  • 4
  • 20

1 Answers1

1

You should probably do add(figure, getChildren().length() which adds your figure to the end of the children list. The ToolbarLayour uses the list order to show the figures, so this should work. Doing add(figure, 0) puts your figure as the first one in the list, so the behavior you see is expected.

vainolo
  • 6,907
  • 4
  • 24
  • 47
  • I was using add(Label, 0) to keep the label at the top. I am adding figures dynamically, through Commands. The command adds the model of the new object in its list. This list adds only the model it is required to add in it, this list doesn't add Label in it as it is not part of the model, instead part of the figure alone. And in the model, I don't have access to getChildren(). – nullpointer Apr 14 '14 at 07:00
  • Since you want to manage how the view looks based on the model, you will have to somehow get a handle to the number of children the view has. This is not best practice, but there is nothing else you can do. – vainolo Apr 18 '14 at 07:13