slodeveloper
slodeveloper

Reputation: 238

Expanding or shrinking size of vaadin calendar component in subwindow

The size of Calendar component in subwindow doesn't expand or shrink to fit the size of subwindow when i click on maximize or minimize button in subwindow.

So i have to click on random button or combobox for vaadin calendar component to fit perfectly in subwindow.

Here are pictures that show my problem:

  1. Subwindow when it's first time opened (OK). Subwindow in normal state (first time opened)
  2. When i click on maximize button (NOT OK). Subwindow in fulscreen state

Code for opening a subWindow:

Window abonWindow = new Window("Abonma");
                        abonWindow.setImmediate(true);
                        abonWindow.setHeight("450px");
                        abonWindow.setWidth("700px");
                        abonWindow.setModal(true);
                        abonWindow.setContent(new AddAbonma(abonWindow));

                        UI.getCurrent().addWindow(abonWindow);

I add all compontents in subwindow with this code:

mainLayout = new AbsoluteLayout();
mainLayout.setImmediate(true);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");

setWidth("100.0%");
setHeight("100.0%");


initCalendar();
initLayoutContent();
initSettingPopupview();


panel_criteria = buildPanel_criteria();
mainLayout.addComponent(panel_criteria, "right:0.0px;top:0.0px;left:0.0px;");

mainLayout.addComponent(calendarComponent, "right:0.0px;top:70.5px;bottom:0px;left:0.0px;");

initCalendar code:

 calendarComponent.setLocale(new Locale("sl","SL"));
                calendarComponent.setImmediate(true);
                calendarComponent.setHeight("100%");
                calendarComponent.setWidth("100%");

This is all code that i have in constructor of SubWindow, i put also addWindowModeChangeListener in it:

buildMainLayout();
setCompositionRoot(mainLayout);
initGui(window);
window.addWindowModeChangeListener(new WindowModeChangeListener() {

    @Override
    public void windowModeChanged(WindowModeChangeEvent event) {

        System.out.println("AddAbonma WindowMode");

        if(calendarComponent!=null){

            calendarComponent.markAsDirtyRecursive();

        }

    }
});  

This approach worked with tables, but does not work with vaadin calendar component.

So how do i expand or shrink vaadin calendar component to fit the subwindow when user click on maximize or minimize button?

Upvotes: 0

Views: 394

Answers (1)

Mika
Mika

Reputation: 1276

You can force Vaadin to recalculate layout with JavaScript. This should not be required and behavior you describe looks like a bug in Vaadin.

You can try something like this. This uses arbitrary timeout of 150 ms because layout recalculating cannot be requested while Vaadin LayoutManager is working and we want to force layout after Vaadin has handled window resizing (and failed to calculate layout).

    Window window = new Window();
    Calendar calendar = new Calendar("Calendar");
    calendar.setWidth("100%");
    window.setWidth("700px");
    window.setHeight("450px");
    window.setContent(calendar);
    window.addWindowModeChangeListener(event -> Page
            .getCurrent()
            .getJavaScript()
            .execute("setTimeout(function() { vaadin.forceLayout(); }, 150);"));
    Button button = new Button("Click me", event -> UI.getCurrent().addWindow(window));
    setContent(button);

Upvotes: 2

Related Questions