【问题标题】:How to resize a DialogBox in GWT so that a FlexTable fits in?如何在 GWT 中调整 DialogBox 的大小以适应 FlexTable?
【发布时间】:2013-08-28 13:21:14
【问题描述】:

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

有人已经做到了吗?

【问题讨论】:

    标签: gwt dialog flextable


    【解决方案1】:

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

    setAnimationEnabled(true);
    

    setAnimationEnabled(false);
    

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

    【讨论】:

    • 我必须更新我的DialogBox 子类。我实际上不使用 GWT 动画,所以我不知道。谢谢!
    【解决方案2】:

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

    【讨论】:

    • 使用您的方法时没有变化。奇怪的是,无论如何高度都很好。只是宽度不正确。实际上,宽度似乎没有超过 400px。当表格变小时,即使是盒子的宽度也是正确的。我只在表格宽度超过 400 像素时看到这个问题。
    猜你喜欢
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    相关资源
    最近更新 更多