سؤال

أنا جديدة على صدى 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;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top