best way to add a layer (example infiniteprogress) to any component

17 views
Skip to first unread message

Rocotoco Rodriguez

unread,
Aug 9, 2017, 8:03:25 AM8/9/17
to CodenameOne Discussions
Hi! im needing to add an adittional layer to any control to implement a infiniteprogress while a query is running.


my aproach was to create a container where the original control is added and there add the second layer, but i dont nowif exist a clearest way to do it where its not neccary to encapsulate the component into another.


my code aproach is:

public class Layer {

    public static Container addLayer(Component con)
    {
        Container layer = new Container();
        layer.getAllStyles().setBgColor(0xff0000);
        layer.getAllStyles().setBgTransparency(100);
       
        //result.setLayout(new BorderLayout());
        con.remove();
        Container result = LayeredLayout.encloseIn(con, layer);
        return result ;
       
       
    }
}


thans.


If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Desktop OS
Simulator
Device

Shai Almog

unread,
Aug 10, 2017, 12:28:28 AM8/10/17
to CodenameOne Discussions
Hi,
there are lots of ways but I'm not sure I can comment on "best" as each has its uses.
Are you adding an infinite progress to the entire form?

Rocotoco Rodriguez

unread,
Aug 10, 2017, 8:33:49 PM8/10/17
to CodenameOne Discussions
No shai, just to the component.

it can be usefull to add and infiniteprogress when a control is loading asyncronously

ideas?

regards and happy hollidays

Shai Almog

unread,
Aug 11, 2017, 2:30:08 AM8/11/17
to CodenameOne Discussions
Why not just use InfiniteProgress with the code you have above instead of the layer container?

Rocotoco Rodriguez

unread,
Aug 11, 2017, 7:53:37 AM8/11/17
to CodenameOne Discussions


im doing that but the problem its that the function returns a container and not the original object type.  can be possible to add the getLayeredPane functionality to the controls who derives from Container?

think in that way, can be possible to add infiniteprogress to containers or labels individually 

thanks
t

Shai Almog

unread,
Aug 12, 2017, 1:19:29 AM8/12/17
to CodenameOne Discussions
The container now wraps the components so you need to do:

Container cnt = LayeredLayout.encloseIn(con, progress);
con
.getParent().replace(con, cnt, null);

Then to remove the infinite progress:

con.remove();
cnt
.getParent().replace(cnt,con, null);

Notice the last argument can be a transition like fade, slide or something else if you so desire.
Reply all
Reply to author
Forward
0 new messages