Curious behavior of Browser Component

36 views
Skip to first unread message

gstv...@gmail.com

unread,
Sep 23, 2015, 11:51:16 AM9/23/15
to CodenameOne Discussions
Hi all, I´ve been working on a mobile application that requieres the use of enriched text; for this, i used the setPage functionality of the Browser Component with HTML tags and kinda works... it displays the text with the format required but just when you tap on the component... if not, it is not shown, anyone has experienced something similar? I forgot; it only happens in the devices, not in the simulator.

Shai Almog

unread,
Sep 23, 2015, 10:51:14 PM9/23/15
to CodenameOne Discussions
Hi,
are you making changes via the EDT?
Do you revalidate after making changes in runtime?

gstv...@gmail.com

unread,
Sep 24, 2015, 11:29:14 AM9/24/15
to CodenameOne Discussions
Hi Shai, thank you for answering,
 
Yeah, i tried using the revalidate and forceRevalidate methods on the main form and on the Container where is the BrowserComponent after doing my changes; i also tried using the BorderLayout on the Container where is the BrowserComponent and setting it in the center; a solution i found somewhere but didn´t work...
 
And no, i´m using a Listener to do the changes; the addPointerReleasedListener and also tried with the addPointerPressedListener i´m not using the EDT
 
Here is the part of the code where i´m talking about
 

labelTexto.addPointerReleasedListener(new ActionListener() {

       @Override

       public void actionPerformed(ActionEvent evt) {

            if(!mapIsComponenteAdd.get(index)){

                  containerTransparente.setUIID("ContenedorTransparenteLista");

                  containerItem.addComponent(1,componentes.get(index));

                  mapIsComponenteAdd.put(index, true);

                  for (int j = 0; j < listaComponentes.size(); j++) {

                      Container container = (Container) listaComponentes.get(j);

                      if(j != index && container.getComponentCount()>1){

                           container.removeComponent(container.getComponentAt(1));

                           mapIsComponenteAdd.put(j, false);

                           Container containerLayered = (Container) ((Container) container.getComponentAt(0)).getComponentAt(2);

                           containerLayered.setUIID("Container");

                      }

                  }

         }

         else{

                containerItem.removeComponent(containerItem.getComponentAt(1));

                mapIsComponenteAdd.put(index, false);

                containerTransparente.setUIID("Container");

         }

         f.revalidate();

     }

});

 
The first bold text part is where the Container that contains the BrowserComponent is setted to the main Container; the second bold text part is where the method revalidate (or forceRevalidate) is applied to the main form, i also tried using the methods in "containerItem" but didn´t work :(
 
And here is the part where the BrowserComponent is created:
 

       BrowserComponent bc = new BrowserComponent();

       bc.setPage("Texto de prueba <b> Texto en negrita</b><i> Texto en cursiva</i><br/>Salto de línea<br/><br/>Doble salto de línea", null);

       bc.setUIID("NoBorderElement");

       bc.setScrollable(false);

       bc.setPreferredH(height);

       containerWB.addComponent(BorderLayout.CENTER, bc);

 
 
Hope the code is readable and thank you in advance for your time.

Shai Almog

unread,
Sep 25, 2015, 12:16:58 AM9/25/15
to CodenameOne Discussions
Hi,
are you using a pointer listener on top of the component?
If so that isn't guaranteed to work, peer components are somewhat self contained and we don't have as much control over them:
https://www.codenameone.com/blog/understanding-peer-native-components-why-codename-one-is-so-portable.html
Reply all
Reply to author
Forward
0 new messages