1
votes

I want to display HTML in my forms. The problem is I have to use a Boxlayout to place my components. So when I put a WebBrowser I'll have some height and scroll issues. I get the HTML I want to display from a webservice. The length of the content is variable. I just want to display a part of this response. Here is what I already have:

enter image description here

The webBrowser is below the edit button and ends near the LBL_LIB_NOM label. As you can see the webBrowser is way too high and I can't scroll the Form when I click over the WebBrowser. In this example I would like to reduce the size of the WebBrowser so we can only see the Title. I also would like if possible to scroll my form when I click on the WebBrowser since I don't want the WebBrowser to scroll.

I have tried a few things to solve my issue:

  • I tried to override the calcPreferredSize method.
  • I revalidate my form and my webbrowser.
  • I resized it's container using the deprecated setPreferedSize method. In that case the container is well sized but the the WebBrowser displays above the other components.

The usual answer I have seen in other posts is to put the WebBrowser in a BorderLayout but I can't do that.

So here is my question: Is there any other component I can use to display one HTML line ? Or is there a way to make a webBrowser work properly in a boxLayout ? Do I have to write my own HTML renderer ?

1

1 Answers

1
votes

I'm guessing you want box layout so you can scroll... This is problematic.

Web views generally expect to scroll themselves and this is common in native widgets which handle their own events and thus scrolling. It's hard for our code to know when your swipe is intended for us or to the underlying native widget and it's harder still to do this in a consistently portable way.

There are 3 options:

  • Use only Codename One code
  • Use a border layout or similar layout
  • Use the web browser for the entire UI of this form

If you want to take the first option this article might be useful as a starting point.