How can i set min-width size for my sub-window in Vaadin?

3.1k Views Asked by At

In my Vaadin code I want to add min-width feature to my sub-window. I set width of my subwindow size %25 of my mainwindow, but I don't want it to be very small.I want it at least "125px". How can i set this with java code?

public class Awindow extends Window{
...
public Awindow(...)
    setModal(true);
    setCaption("Hello");
    this.setHeight("100%");
    this.setWidth("25%");// I don't want it to be %25 all the time,I want it to remain still after "150px".

    VerticalLayout layout = new VerticalLayout (
        memberTable,
        new HorizontalTable(
             createButton,
             eraseButton)
    );
    layout.setSpacing(true);
    ...
    this.setContent(layout);
3

There are 3 best solutions below

2
On

The only possible solution i know is to make it with css.

You can add a css for the .v-window class eg:

.v-window {
      min-width: 125px !important;
 }
0
On

As long as https://github.com/vaadin/framework/issues/1360 is not implemented by Vaadin, you might want to check out the following add-on: https://vaadin.com/directory#!addon/restrain. This does essentially the same as proposed by the other answers, but has a nice server side api.

E.g.:

new Restrain(component).setMinWidth("125px");
0
On

If you want fully programically
1) add your css style to page style with programmically

UI.getCurrent().getPage().getStyles().add(".min125px{min-width: 125px !important;}");

2) add this style (min125px) to your buttons

createButton.addStyleName("min125px");
eraseButton.addStyleName("min125px");