Reto Höhener
Reto Höhener

Reputation: 5808

Can CssLayout be used to achieve absolute positioning of components?

Currently I am using AbsoluteLayout, but because of some problems I would like to give CssLayout a try.

I would like to dynamically place image-, label- and button-components at specific positions in the layout.

AbsoluteLayout allows me to specify the position like so:

absoluteLayout.addComponent(component, "top:20px;left:20px")

Is something like this at all possible to achieve with CssLayout?

Upvotes: 1

Views: 335

Answers (1)

Henri Kerola
Henri Kerola

Reputation: 4967

You can apply inline CSS for a component by overriding getCss on CssLayout, so the following should have the wanted result:

  CssLayout cssLayout = new CssLayout() {
    @Override
    protected String getCss(Component component) {
        // check the component here and return correct css. In this case only one component in the layout so this works..
        return "position: relative; top: 10px; left: 10px";
    }  
  };
  cssLayout.setSizeFull();

  cssLayout.addComponent(new Button("Hello"));

Upvotes: 2

Related Questions