【问题标题】:GWT lazy loadingGWT 延迟加载
【发布时间】:2023-03-26 13:33:01
【问题描述】:

GWT 有 LazyPanel 吗?我看不到它。请告诉我。如果有lazyPanel,请让我知道版本

【问题讨论】:

    标签: gwt gwt-ext


    【解决方案1】:

    我同意rustyshelf关于谷歌搜索的原则,但是由于StackOverflow本身也是一个参考,这里给出一个更详细的答案:

    默认情况下,LazyPanel 不显示。只有在 LazyPanel 上调用 setVisible(true) 时才会创建底层小部件。

    当子面板包含相对较重的内容时,此类主要应与 StackPanel、DisclosurePanel 和 TabPanel 结合使用。
    使用LazyPanel 包装这些内容的创建可以显着改善用户体验。


    Using the LazyPanel is simple。您需要做的就是将要延迟加载的小部件添加到延迟面板中,然后在延迟面板上调用 setVisible(true) 以实际按需加载小部件。值得一提的是,LazyPanel 主要用于 TabPanel 和 StackPanel 等小部件,并非在所有情况下都理想。

    【讨论】:

    • 不能与评分和你一样高的人争论,先生,我向你致敬;)
    【解决方案2】:

    这是来自“候选版本”GWT 1.6.2 的 LazyPanel.java 所以是的,很简单,并且确认了上面的答案。

    /*
     * Copyright 2008 Google Inc.
     * 
     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
     * use this file except in compliance with the License. You may obtain a copy of
     * the License at
     * 
     * http://www.apache.org/licenses/LICENSE-2.0
     * 
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     * License for the specific language governing permissions and limitations under
     * the License.
     */
    
    package com.google.gwt.user.client.ui;
    
    /**
     * Convenience class to help lazy loading. The bulk of a LazyPanel is not
     * instantiated until {@link #setVisible}(true) or {@link #ensureWidget} is
     * called.
     * <p>
     * <h3>Example</h3> {@example com.google.gwt.examples.LazyPanelExample}
     */
    public abstract class LazyPanel extends SimplePanel {
    
      public LazyPanel() {
      }
    
      /**
       * Create the widget contained within the {@link LazyPanel}.
       * 
       * @return the lazy widget
       */
      protected abstract Widget createWidget();
    
      /**
       * Ensures that the widget has been created by calling {@link #createWidget}
       * if {@link #getWidget} returns <code>null</code>. Typically it is not
       * necessary to call this directly, as it is called as a side effect of a
       * <code>setVisible(true)</code> call.
       */
      public void ensureWidget() {
        Widget widget = getWidget();
        if (widget == null) {
          widget = createWidget();
          setWidget(widget);
        }
      }
    
      @Override
      /*
       * Sets whether this object is visible. If <code>visible</code> is
       * <code>true</code>, creates the sole child widget if necessary by calling
       * {@link #ensureWidget}.
       * 
       * @param visible <code>true</code> to show the object, <code>false</code> to
       * hide it
       */
      public void setVisible(boolean visible) {
        if (visible) {
          ensureWidget();
        }
        super.setVisible(visible);
      }
    }
    

    【讨论】:

    • LazyPanel 包含在 1.6 版本中,其中 1.6.4 是第一个“官方”发布版本。
    猜你喜欢
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-06
    相关资源
    最近更新 更多