1

我想FlexTable在 a 中使用 a DialogBox。的大小DialogBox应与 的大小相匹配FlexTable。不幸的是,DialogBox它更小,因此FlexTable被切割并且只有部分可见。有没有办法自动调整大小以DialogBox适应FlexTable?(请注意,在FlexTable显示时不会改变,所以一旦显示在屏幕上就不需要自动调整大小......)

有人已经做到了吗?

4

2 回答 2

2

我想我现在发现出了什么问题。除了 Bryan 的出色答案外,这在这种情况下也可能有所帮助(尽管在我的情况下,自动调整大小和 Bryan 的方法之间没有变化)。我发现在使用动画时,DialogBoxGWT 中 a 的宽度限制为 400 像素。换线时

setAnimationEnabled(true);

setAnimationEnabled(false);

DialogBox 的大小可以正常工作。也许这对某人有帮助......

于 2013-08-29T10:31:54.973 回答
1

在我的应用程序中,我创建了一个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 后,您需要推迟一次getOffsetHeightandgetOffsetWidth调用,以获得一致、有效的结果。

于 2013-08-29T03:57:20.530 回答