Best way to reuse a container full of components

59 views
Skip to first unread message

Gareth Murfin

unread,
Oct 22, 2013, 2:24:27 PM10/22/13
to codenameone...@googlegroups.com
Right now each of my pages have a standard header, and many of them a standard footer (by this I mean a container containing other containers and bullets etc with various layouts etc). For now once I get it right I simply copy and paste it to my other forms which is really no big deal, but when you come to change that header then of course you need to change it on every form. Is there some neater way to do this so each one can point to a single "base", ie, I make one change to the header, it happens everywhere else I have used a header.

It would be nice if you could some how save out your own container and everything within it as some sort of "prefab" that you can drop in, and when you edit the prefab the instances of it all change too. 

Just a thought, I know this is extremely hard to achieve, in many ways I think if you exposed the underlying data structures as XML or something, then we could edit like you might in dreamweaver, half gui half markup language, and instantiate sub xml files as components - but then thats simply exactly what android did, and my own system before :-) Would be good to hear your thoughts on reusing things basically.

Rikard Lindgren

unread,
Oct 22, 2013, 3:05:47 PM10/22/13
to codenameone...@googlegroups.com
Not sure if this is what you are looking for, but you can use the Embed Container to achieve something similar to what you are asking for.
The Embed Container let´s you embed another GUI Element. So in your case i would create the Header and Footer as separate GUI elements and then use the Embed Container to add them to each page.

Gareth Murfin

unread,
Oct 22, 2013, 4:34:32 PM10/22/13
to codenameone...@googlegroups.com
That sounds exactly what Im looking for! Thanks very much I will look into it!!! I guess I need to RTFM asap too ! :-))) thanks again

Jaanus Kiipli

unread,
May 15, 2020, 11:19:08 AM5/15/20
to CodenameOne Discussions
Sorry for stupid question, but how to do that? is there a way to embed container using the GUIBuilder or should I fiddle in the xml files manually or in the java code or how?

Gareth Murfin

unread,
May 15, 2020, 12:58:57 PM5/15/20
to CodenameOne Discussions
actually its really easy, in gui builder make a "container" not a "form".. then you can just get it and put it inside a container in another screen, some example code 

 Container ContainerNORTHinset = (Container)findByName("ContainerNORTHinset",f);//the place (on your current form) where you want to add your reusable container
        ContainerNORTHinset.removeAll();//make sure its empty
        Container IncludeStudentLifeHeaderSelectTerm  =  (Container)createContainer(r, "IncludeStudentLifeHeaderSelectTerm"); //HERE you instance your container
        ContainerNORTHinset.add(BorderLayout.CENTER,IncludeStudentLifeHeaderSelectTerm);//add it to the form

viola, u may also sometimes need

 f.revalidate();
Reply all
Reply to author
Forward
0 new messages