How to know used component height?

How to get the “used” height (that was set by terminal) of a component with unspecified height?

Thanks!

Hi!

This is not possible server-side, but client-side (using GWT) you can retrieve the dimensions of a component e.g.
by calling getElement().getOffsetHeight() in your widget. You could probably extend any Vaadin component to pass this value back to the server-side.

HTH,
/Jonatan

Thanks Jonantan,

The question was because i want to achieve the pattern of google docs main page.

Explanation:
I have a horizontal Splitpane and in the second component i put:

  • On top: A HorizontalLayout with action buttons (topHorizontalLayout)
  • On remain space: A table with results items (table)

I want preserve that the only visible scroll is the table scroll (like google docs).

Until now, the only way to achieve this, was setting a fixed height to table. If i know the topHorizontalLayout height, i set the table height to (spliter.Height- topHorizontalLayout.usedHeight)… but unspecified height returns -1.

So… this is the right way?
There are alternatives?
And, what happen when window resizes?!

Thanks again!

Hi again,

You should probably be using relative sizes, i.e. set your table to 100% high and 100% wide (
setSizeFull()
). This should make the table as big as possible in the splitpanel. Remember that if you have any layouts wrapping the table, you need to specify the size for them as well.

The only problem would be placing the splitter in the splitpanel correctly regarding the size of your layout with action buttons. I’m afraid I don’t have any good solution for this other than a good default.

Search the forums for setSizeFull for more specifics on relative sizing.

/Jonatan

Hi,

Finally, the question was solved.
The expected result is on screen shot attached.
And the code is:


public class MyApplication extends Application {

    @Override
    public void init() {
        Window mainWindow = new Window("MyApplication");
        SplitPanel splitPanel = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL);
        splitPanel.setSplitPosition(25);
        splitPanel.setLocked(true);
[b]
        splitPanel.setSizeFull();
[/b]
        splitPanel.setFirstComponent(new Label("Tree with options..."));
        VerticalLayout verticalLayout = new VerticalLayout();
        splitPanel.setSecondComponent(verticalLayout);
[b]
        verticalLayout.setSizeFull();
[/b]
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        horizontalLayout.setSpacing(true);
        horizontalLayout.addComponent(new Button("Action 1"));
        horizontalLayout.addComponent(new Button("Action 2"));
        horizontalLayout.addComponent(new Button("Action 3"));
        verticalLayout.addComponent(horizontalLayout);
        Table table = new Table();
        table.setContainerDataSource(VaadinExampleUtils.getISO3166Container());
[b]
        table.setSizeFull();
[/b]
        verticalLayout.addComponent(table);
[b]
        verticalLayout.setExpandRatio(table, 1.0f);
[/b]
        mainWindow.setContent(splitPanel);
        setMainWindow(mainWindow);
    }
}

As Jonatan post said, the answer was set SizeFull properly.

Thanks again Jonatan.
11241.png