Echo2:如何创建居中的窗格?

时间:2020-03-06 14:55:35  来源:igfitidea点击:

我是Echo 2框架的新手。我认为这应该很简单,但是我没有找到将生成的内容水平和垂直居中放置的方法。
是否有可能获得具有固定宽度和高度的居中ContentPane(或者类似内容)?

谢谢,
安德烈

解决方案

使用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;
}