529/5000 Container List does not display new records on a Tab Component.

37 views
Skip to first unread message

rvill...@cableonda.com

unread,
Dec 21, 2016, 8:28:18 AM12/21/16
to CodenameOne Discussions
Hi,

Create a small app to show my problem. When you press the security icon (in the menu bar) a new record is created in a vector. The list of containers can be seen by executing the "muestraPrueba" method from the list of commands ("Validate"). This list is not displayed on the "Tab" component.

I'm really frustrated because I have 4 weeks with the problem and I can not find the solution.

My code below:

public class Liber {

    private Form current;
    private Resources theme;
    private Datos dT;
    private Container cnLiber1;
    private Container cnLiber2;
    private Container cnLiber3;

    public void init(Object context) {
        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);
    }

    public void start() {
        if (current != null) {
            current.show();
            return;
        }
        dT = Datos.getInstancia();
        muestraLiber();
    }

    public void stop() {
        current = Display.getInstance().getCurrent();
        if (current instanceof Dialog) {
            ((Dialog) current).dispose();
            current = Display.getInstance().getCurrent();
        }
    }

    public void destroy() {
    }

    // Método que muestra la  Forma Principal
    private void muestraLiber() {

        final Form fmLiber = new Form();
        fmLiber.setTitle("Prueba");
        fmLiber.setLayout(new BorderLayout());

        Command cmdSalir = new Command("Salir") {
            public void actionPerformed(ActionEvent ev) {
                Display.getInstance().exitApplication();
            }
        };

        final Toolbar tbMenu = new Toolbar();
        fmLiber.setToolBar(tbMenu);
        Style s = UIManager.getInstance().getComponentStyle("Title");

        FontImage iNuevo = FontImage.createMaterial(FontImage.MATERIAL_SECURITY, s);
        tbMenu.addCommandToRightBar(new Command("", iNuevo) {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Vector vDato = dT.getDato();
                vDato.addElement("Record ");
                dT.setDato(vDato);
                Dialog.show("New", "Add The New Record", "Continue", null);
            }
        });
        Command cmdValidacion = new Command("Validar") {
            public void actionPerformed(ActionEvent ev) {
                muestraPrueba(fmLiber);
            }
        };
        tbMenu.addCommandToOverflowMenu(cmdValidacion);

        cnLiber1 = muestraCompra1();
        cnLiber2 = muestraCompra1();
        cnLiber3 = muestraCompra1();

        final Tabs tsMenu = new Tabs();
        tsMenu.addTab("Compras", cnLiber1);
        tsMenu.addTab("Listas", cnLiber2);
        tsMenu.addTab("Novedades", cnLiber3);

        tsMenu.addSelectionListener(new SelectionListener() {
            @Override
            public void selectionChanged(int oldSelected, int newSelected) {
                if (newSelected == 0) {
                    cnLiber1 = muestraCompra1();
                }
                if (newSelected == 1) {
                    cnLiber2 = muestraCompra1();
                }
                if (newSelected == 2) {
                    cnLiber3 = muestraCompra1();
                }
            }
        });
        fmLiber.addComponent(BorderLayout.CENTER, tsMenu);
        fmLiber.setBackCommand(cmdSalir);
        fmLiber.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 500));
        fmLiber.show();
        fmLiber.revalidate();
    }

    private Container muestraCompra1() {

        Container compra1 = new Container(BoxLayout.y());
        compra1.setScrollableY(true);
        compra1.setUIID("Form");
        Vector vDato = dT.getDato();
        for (int i = 0; i < vDato.size(); i++) {
            compra1.add(creaContenedorCompra("Prueba" + i));
        }
        return compra1;
    }

    private Container creaContenedorCompra(String dato) {
        Container cn = new Container(new BorderLayout());
        cn.addComponent(BorderLayout.CENTER, new Label(dato));
        return cn;
    }

    private void muestraPrueba(final Form fmLiber) {
        final Form fmPrueba = new Form();
        fmPrueba.setLayout(new BorderLayout());
        fmPrueba.setScrollable(false);

        Command cmdVolver = new Command("Volver") {
            public void actionPerformed(ActionEvent ev) {
                fmLiber.showBack();
            }
        };
        Container cn2 = muestraCompra1();
        fmPrueba.addComponent(BorderLayout.CENTER, cn2);
        fmPrueba.setBackCommand(cmdVolver);
        fmPrueba.setTransitionOutAnimator(CommonTransitions.createSlide(
                CommonTransitions.SLIDE_HORIZONTAL, true, 500));
        fmPrueba.show();
    }
}


public class Datos {
    private static Datos instancia = null;
    private Vector dato = new Vector();
    
    private Datos() {
        
    }
    
    public static Datos getInstancia() {
        if (instancia == null) {
            instancia = new Datos();
        }
        return instancia;
    }
        
    public Vector getDato() {
        return dato;
    }
    
    public void setDato(Vector dato) {
        this.dato = dato;
    }
}


Shai Almog

unread,
Dec 22, 2016, 2:52:32 AM12/22/16
to CodenameOne Discussions, rvill...@cableonda.com
Hi,
this is a bit hard to follow also some screenshots would help.
I don't understand what you re doing here:

rvill...@cableonda.com

unread,
Dec 27, 2016, 2:13:39 PM12/27/16
to CodenameOne Discussions, rvill...@cableonda.com

Hi,


Figure 1, shows a form with the tab component that has 3 tabs. Each tab displays a list of containers. For this example what I do is add a record to a vector (by pressing the security icon) which should be displayed as a new container on any of the tabs.


Figure 2 shows the message of the record to be created.


Figure 3 shows the list of containers in a form that is launched from the list of commands (this is the information that should appear in each tab).


My question is: Why does the list of containers appear on the form and not on the tabs?





Shai Almog

unread,
Dec 28, 2016, 1:22:25 AM12/28/16
to CodenameOne Discussions, rvill...@cableonda.com
Hi,
check scrollability of the form vs. the tab container.

Also if you added something after the tab was shown make sure to revalidate.

rvill...@cableonda.com

unread,
Dec 29, 2016, 2:19:04 AM12/29/16
to CodenameOne Discussions, rvill...@cableonda.com
Hi,
I made the changes but the result is the same. I copy the main method to see if it finds something.

My code:
 // Método que muestra la  Forma Principal
    private void muestraLiber() {

        final Form fmLiber = new Form();
        fmLiber.setTitle("Prueba");
        fmLiber.setLayout(new BorderLayout());
        fmLiber.setScrollableY(true);

        Command cmdSalir = new Command("Salir") {
            public void actionPerformed(ActionEvent ev) {
                Display.getInstance().exitApplication();
            }
        };

        final Toolbar tbMenu = new Toolbar();
        fmLiber.setToolBar(tbMenu);
        Style s = UIManager.getInstance().getComponentStyle("Title");

        FontImage iNuevo = FontImage.createMaterial(FontImage.MATERIAL_SECURITY, s);
        tbMenu.addCommandToRightBar(new Command("", iNuevo) {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Vector vDato = dT.getDato();
                vDato.addElement("Record ");
                dT.setDato(vDato);
                Dialog.show("New", "Add The New Record", "Continue", null);
                cnLiber1.revalidate();
                cnLiber2.revalidate();
                cnLiber3.revalidate();
            }
        });
        Command cmdValidacion = new Command("Validar") {
            public void actionPerformed(ActionEvent ev) {
                muestraPrueba(fmLiber);
            }
        };
        tbMenu.addCommandToOverflowMenu(cmdValidacion);

        cnLiber1 = muestraCompra1();
        cnLiber2 = muestraCompra1();
        cnLiber3 = muestraCompra1();

        cnLiber1.setScrollableY(true);
        cnLiber2.setScrollableY(true);
        cnLiber3.setScrollableY(true);

        final Tabs tsMenu = new Tabs();
        tsMenu.addTab("Compras", cnLiber1);
        tsMenu.addTab("Listas", cnLiber2);
        tsMenu.addTab("Novedades", cnLiber3);

        tsMenu.addSelectionListener(new SelectionListener() {
            @Override
            public void selectionChanged(int oldSelected, int newSelected) {
                cnLiber1.revalidate();
                cnLiber2.revalidate();
                cnLiber3.revalidate();

Shai Almog

unread,
Dec 30, 2016, 12:12:44 AM12/30/16
to CodenameOne Discussions, rvill...@cableonda.com
Hi,
setScrollableY() won't work with border layout. Codename One doesn't allow nesting scrollables and scrolling within a border layout isn't allowed either.
The content of each tab needs to be scrollable appropriately.

What's the code that adds the list to the tab?
Reply all
Reply to author
Forward
0 new messages