Horizontally centering a popup window in Vaadin
<p>I have added a popup window to my main UI as follows:</p>

<pre><code>Window component = new Window();
UI.getCurrent().addWindow(component);
</code></pre>

<p>Now, I want my popup to be centered horizontally and e.g. 40 pixels from the top of the screen. As far as I can see Vaadin has 4 methods for positioning my window.</p>

<pre><code>component.center()
component.setPosition(x, y)
component.setPositionX(x)
component.setPositionY(y)
</code></pre>

<p>None of these are really what I want. I was hoping at first that setPositionY might help me. This does allow me to get the right distance from the top, but the x-position is now set to 0, where I wanted it to be centered.</p>

<p>The setPosition might have helped if I was able to calculate what the x-position should be, but this would require me to know the width of the component in pixels, but component.getWidth just tells me 100%.</p>

<p>Next I tried to use CSS styling on the component, writing and explicit css rule and adding it to the component with addStyleName. It seems though that Vaadin overrides whatever I wrote in my css with its own defaults...</p>

<p>Any ideas how to get my Window component positioned correctly?</p>