Skip to main content

Cyclic focus and too much screen to scroll. Bug or bad code?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
9 replies [Last post]
enekonieto
Offline
Joined: 2010-12-15

Hello,

I have developed a method for composing a form with an optional top text, an optional centre image and an optional bottom text. All of them are expected to be large, even bigger than screen. There are some details I haven't get done but I have spent a few days with LWUIT so I don't know if they are bugs or simply my fault.

First my problems:

1) If the bottom text is set the form is much bigger than needed. Can see in the following screenshots:
http://dev.bxmobile.com/test/lwuit1.png
http://dev.bxmobile.com/test/lwuit2.png
http://dev.bxmobile.com/test/lwuit3.png

2) I set cyclic focus to false but focus is still cyclic. Can see in the following screenshots:
http://dev.bxmobile.com/test/lwuit4.png
http://dev.bxmobile.com/test/lwuit5.png

3) If I don't use f.getContentPane().revalidate() after adding components these don't scroll as expected. I am just curious for better understand the reason.

And now the code, with empty top text, a medium image and a large bottom text:

	public static void mostrarPantallaTextoImagenLWUIT(ActionListener listener, String titulo, String textoSuperior, String textoInferior, Image imagen, int skin, Fondo fondo, int colores[], com.sun.lwuit.Command[] cmds) {
Form f = new Form(titulo);
f.setCyclicFocus(false);

//textoSuperior = "abcdebfg ijkladfñiadsgnle adfadfidsafñdakjiñadfidafinkkekekkkkfaeae dafadf adfad adf e efe  faef  a faef  aefek abcdebfg ijkladfñiadsgnle adfadfidsafñdakjiñadfidafinkkekekkkkfaeae dafadf adfad adf e efe  faef  a faef  aefek abcdebfg ijkladfñiadsgnle adfadfidsafñdakjiñadfidafinkkekekkkkfaeae dafadf adfad adf e efe  faef  a faef  aefek abcdebfg ijkladfñiadsgnle adfadfidsafñdakjiñadfidafinkkekekkkkfaeae dafadf adfad adf e efe  faef  a faef  aefek abcdebfg ijkladfñiadsgnle adfadfidsafñdakjiñadfidafinkkekekkkkfaeae dafadf adfad adf e efe  faef  a faef  aefek abcdebfg ijkladfñiadsgnle adfadfidsafñdakjiñadfidafinkkekekkkkfaeae dafadf adfad adf e efe  faef  a faef  aefek abcdebfg ijkladfñiadsgnle adfadfidsafñdakjiñadfidafinkkekekkkkfaeae dafadf adfad adf e efe  faef  a faef  aefek ";
textoSuperior = "";

textoInferior = "12345678901234567890123456789012345678901234567890 1234567890 1234567890123456789012345678901234567890\nlinea sola\n1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 bbbbbbbbbbbbbbbbbbbbb";

try {
imagen = Image.createImage("/img/logo.png");
} catch (IOException ioe) { ioe.printStackTrace(); }

if ((textoSuperior != null) && !"".equals(textoSuperior)) {
TextArea taSuperior = new TextArea(textoSuperior);
taSuperior.getStyle().setBorder(null);
taSuperior.setEditable(false);
f.addComponent(taSuperior);
}

if (imagen != null)
f.addComponent(new Label(com.sun.lwuit.Image.createImage(imagen)));

if ((textoInferior != null) && !"".equals(textoInferior)) {
TextArea taInferior = new TextArea(textoInferior);
taInferior.getStyle().setBorder(null);
taInferior.setEditable(false);
f.addComponent(taInferior);
}

f.getContentPane().revalidate();

for (int i = 0; i < cmds.length; i++)
f.addCommand(cmds[i]);

f.addCommandListener(listener);

f.show();
}

Thanks in advance

Eneko

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07

Check that you are working on the EDT, its critical to be on the EDT when using text area's extensively.

enekonieto
Offline
Joined: 2010-12-15

Hi, I checked and it's on the unique thread of the application. This thread is the EDT or do I need to do something special for launching EDT (use Display.callSerially or something similar)?
Here is a screenshot to show it is the unique thread (emulator thread is always present and has nothing to do with the midlet):
http://dev.bxmobile.com/test/lwuit6.png
Thanks in advance
Eneko

vprise
Offline
Joined: 2003-11-07

That doesn't seem like the EDT. You can check using Display.getInstance().isEDT(), you can use callSerially to get into the EDT.
Notice that the LWUIT event thread is DIFFERENT from the MIDP event thread so MIDP's callSerially != LWUIT's callSerially!

enekonieto
Offline
Joined: 2010-12-15

Thanks for the help, I didn't know about the need to use callSerially. Now I use it and isEdt() returns true but unfortunately, still have same issues (form too big and cyclic focus).

final ActionListener listener_ = listener;
        final String titulo_ = titulo;
        final String textoSuperior_ = "";
        final String textoInferior_ = "12345678901234567890123456789012345678901234567890 1234567890 1234567890123456789012345678901234567890\nlinea sola\n1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890  1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
try {
imagen = Image.createImage("/img/logo.png");
} catch (IOException ioe) { ioe.printStackTrace(); }
        final Image imagen_ = imagen;
        final com.sun.lwuit.Command[] cmds_ = cmds;
      
        Runnable r = new Runnable() {
            public void run() {
          
          
        Form f = new Form(titulo_);
        f.setCyclicFocus(false);
      
System.out.println("EDT="+com.sun.lwuit.Display.getInstance().isEdt());
      
      
        if ((textoSuperior_ != null) && !"".equals(textoSuperior_)) {
            TextArea taSuperior = new TextArea(textoSuperior_);
            taSuperior.getStyle().setBorder(null);
            taSuperior.setEditable(false);
            f.addComponent(taSuperior);
        }
        if (imagen_ != null)
            f.addComponent(new Label(com.sun.lwuit.Image.createImage(imagen_)));
        if ((textoInferior_ != null) && !"".equals(textoInferior_)) {
            TextArea taInferior = new TextArea(textoInferior_);
            taInferior.getStyle().setBorder(null);
            taInferior.setEditable(false);
            f.addComponent(taInferior);
        }
        // Refrescamos el formulario para que se organice correctamente.
        f.getContentPane().revalidate();
  
        for (int i = 0; i < cmds_.length; i++)
            f.addCommand(cmds_[i]);
        f.addCommandListener(listener_);

        pantallaActualLWUIT = f;
        f.show();
      
            }
        };
        com.sun.lwuit.Display.getInstance().callSerially(r);

Any ideas? Thanks in advance
Eneko

vprise
Offline
Joined: 2003-11-07

When constructing the text area try to set the columns to a larger size e.g. 30 or so. This will help the size calculation algorithm get the right result the first time around.

enekonieto
Offline
Joined: 2010-12-15

No luck :(
Changed "TextArea taInferior = new TextArea(textoInferior_);" to "TextArea taInferior = new TextArea(textoInferior_, 1, 100);" (tried with 30 colums too) and the behaviour is the same, screen is too large and scroll is cyclic.
I am using current SVN version and testing with WTK emulator and Nokia 5800 XpressMusic, same behaviour on both.
Thank you for your help vprise.
Eneko

vprise
Offline
Joined: 2003-11-07

Can you please file an issue with the image required for your sample attached (as well as compilable code). I'll take a look at it in the issue tracker.

enekonieto
Offline
Joined: 2010-12-15

Hi, issue 406 filled:
https://lwuit.dev.java.net/issues/show_bug.cgi?id=406
Thanks in advance

vprise
Offline
Joined: 2003-11-07

Thanks I'll look at it once I clean some of my existing tasks.