Search code examples
panelcenterecho2

Echo2: How to create a centered Pane?


I'm new to the Echo 2 framework. I think it should be simple, but I found no way to center the generated content horizontally and vertically. Is there any possibility to get a centered ContentPane (or something similar) with a fixed width and height?

thx, André


Solution

  • Found the solution with echoPointNG:

    public static ContainerEx createCenteredPane( int width, int height ) {
        ContainerEx cp = new ContainerEx();
        cp.setPosition( Positionable.ABSOLUTE );
        cp.setOutsets( new Insets( width / 2 * -1, height / 2 * -1, 0, 0 ) );
        cp.setWidth( new Extent( width ) );
        cp.setHeight( new Extent( height ) );
        cp.setLeft( new Extent( 50, Extent.PERCENT ) );
        cp.setTop( new Extent( 50, Extent.PERCENT ) );
        return cp;
    }