私のアプリケーションではDialogBox
、テーブルのサイズを正確に判断できるようにモーダルがいつ画面に表示されるかを知る必要があるため、処理がはるかに簡単になるサブクラスを作成しました。
public class Modal extends DialogBox
{
private VerticalPanel myContentPanel;
private FlexTable myTable;
public Modal( )
{
...
// Construct the modal and call `setWidget()` with something like a `VerticalPanel`
super.setWidget( this.myContentPanel );
}
@Override
public void onAttach( )
{
// This is called when the modal attaches to the DOM:
super.onAttach( );
// Heights still aren't quite valid, we need to defer the call one more frame.
// Make ourselves invisible while we defer the call so we don't flicker:
super.setVisible( false );
// Defer until the next frame:
Scheduler.get( ).scheduleDeferred( new ScheduledCommand( )
{
@Override
public void execute( )
{
// Height on the table is now valid:
int width = myTable.getOffsetWidth( );
int height = myTable.getOffsetHeight( );
// Update the heights:
Modal.this.myContentPanel.setSize( width + "px", height + "px" );
Modal.this.setSize( width + "px", height + "px" );
// Center and show ourselves:
Modal.this.center( );
Modal.this.setVisible( true );
}
});
}
}
私の経験では、一貫性のある有効な結果を得るには、ウィジェットが DOM にアタッチされた後に getOffsetHeight
andの呼び出しを延期する必要があることがわかりました。getOffsetWidth