Search code examples
javagwtuibinder

GWT with UIBinder - how to programatically add ScrollPanel?


i want to programatically create scrollPanel inside

    <g:FlowPanel ui:field="viewDynamicContent"></g:FlowPanel>

Code for scrollPanel generating is as follows:

    ScrollPanel scrollPanel = new ScrollPanel();
    FlowPanel flowPanel =  new FlowPanel();

    scrollPanel.addStyleName("standard-scroll-panel standard-content-bckgr");

    final HTML emptyInfo = new HTML();
    emptyInfo.setHTML(new SafeHtml() {
        @Override
        public String asString() {
            String html = "";
            html += "<div>";
            html += "<p>" + SEARCH_EVENTS_LIST_EMPTY + "</p>";
            html += "<p>";
            html += "<span class='font-color-cyan'>" + SEARCH_EVENTS_LIST_EMPTY_2 + "</span>";
            html += "</p>";
            html += "</div>";

            return html;
        }
    });
    emptyInfo.addStyleName("standard-warning-panel text-center");

    flowPanel.add(emptyInfo);
    scrollPanel.add(flowPanel);

    viewDynamicContent.add(scrollPanel);

The problem is, i can get proper html structure with this code but unfortunately i can't scroll. After moving scrollPanel in any direction, it's always coming back to default position. After adding ScrollPanel widget inside HTML structure everything is ok, but in this specific case i need to completely create this element inside java function.


Solution

  • You have to set size of ScrollPanel in some way, either setting in explicitly or putting ScrollPanel inside some panel which ProvidesResize.