1

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

4

2 回答 2

2

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

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

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


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

于 2008-12-20T11:42:28.873 回答
0

这是来自“候选版本”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);
  }
}
于 2009-03-26T02:05:04.307 回答