P5music
P5music

Reputation: 3327

CodenameOne - BrowserComponent not scrollable

This sample project (downloaded the "bare-bones" project) shows a BrowserComponent that does not scroll.

By the way, the bare-bones project (created by their online template generator) does not work (!) because one file is missing. I copied that file from another CN1 project of mine (the one from this issue comes in fact) into the sample project and it now compiles.

public class MyApp extends Lifecycle 
{
@Override
public void runApp() 
{
    Form hi = new Form("Hi World", new BorderLayout());
    //Form hi = new Form("Hi World", new BoxLayout.y()); alternate version
    hi.setScrollable(false); //you can also comment this one
    hi.setScrollableY(false);//you can also comment this one
    hi.setScrollableX(false);//you can also comment this one
    Button helloButton = new Button("Hello World");
    hi.add(BorderLayout.NORTH,helloButton);
    //hi.add(helloButton); alternate version
    helloButton.addActionListener(e -> hello());
    hi.getToolbar().addMaterialCommandToSideMenu("Hello Command",
            FontImage.MATERIAL_CHECK, 4, e -> hello());
    Container mainContainer=new Container(new BorderLayout());
    BrowserComponent bc=new BrowserComponent();
    
    bc.setScrollable(true);
    bc.setScrollableY(true);

    bc.setPage("<HTML><BODY><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P><P>TEXT</P></BODY></HTML>",""); // it's a long page so it can be scolled

    //mainContainer.add(BorderLayout.CENTER,bc); alternate version
    //hi.add(BorderLayout.CENTER,mainContainer); alternate version
    hi.add(BorderLayout.CENTER,bc);
    hi.show();
}

private void hello() {
    Dialog.show("Hello Codename One", "Welcome to Codename One", "OK", null);
}

}

Am I missing something important to make it scrollable by the user with touch?

I compiled several different versions, encompassing centering the BC inside the form or the container and so on (see commented lines).

I tested it on the CN1 simulator and a real Android device (server build), it is not scrollable (text is selected instead). I followed all their advice so the BC is centered in BorderLayout, and the form is set not scrollable.

I remember that my real app was working at some point. Now I tested my app and I see it does not work, so I made this sample app. Maybe I am wrong.

This is not a beginner's question, it's about the BC having issues. I know such a component is flacky on many systems, like also important ones like SwiftUI for example, but certainly it is on CN1.

On the CN1 simulator the scrollbars always appear, so I could test it, and the BC is scrollable by using the scrollbars. But mouse events are not correctly handled.

I have many workarounds in my real project to handle mouse events inside the BC, but the sample project here is a very simple project with just the BC.

It is not unlikely that the BC was broken by some recent updates to fix something else.

So what is the solution now?

Upvotes: 1

Views: 40

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

You set the browser component wrapper to scrollable which effectively blocks the native scrolling within the browser component. Just don't call any setScrollable anything and scrolling will work for the case of a border layout.

Upvotes: 0

Related Questions