自定义 gxt Cell 可能需要 Widget

2022-01-18 00:00:00 grid gwt java gxt

我需要一个可以在其中放置小部件的列.我有这个:

I need a Column in which it was possible to put a Widget. I have this:

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Widget;

public class WidgetGridCell extends AbstractCell<Widget> {

    Widget widget;

    public WidgetGridCell(Widget widget) {
        this.widget = widget;
    }

    @Override
    public void render(Context paramContext,
            Widget param, SafeHtmlBuilder pb) {

    }
}

但我不知道如何在 HTML 中包含小部件

But I do not know how to include the widget in HTML

附:或者不是 Widget,只有 GWT Button 适合我.

P.S. Or not Widget, only GWT Button will suit me.

推荐答案

参见这里 了解 AbstractCell 实现的一些示例.

See here for a number of examples of AbstractCell implementations.

要回答有关 GWT 按钮的问题:

To answer your question regarding a GWT button:

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Widget;

public class WidgetGridCell extends AbstractCell<Widget> {

  Widget widget;

  public WidgetGridCell(Widget widget) {
      this.widget = widget;
  }

  @Override
  public void render(Context paramContext,
          Widget param, SafeHtmlBuilder pb) {
    Button aButton = new Button();
    // add text to the button, etc...
    pb.append(SafeHtmlUtils.fromTrustedString(aButton.toString()));
  }
}

尝试在单元格元素中渲染整个小部件在很大程度上是不可行的(也不可取),但听起来好像您真的在尝试从单元格中渲染按钮.

It's largely not feasible (and not advisable) to try and render an entire widget within a cell element but it sounds as though you are really trying to render a button from within the cell.

AbstractCell 是 Cell 接口的一个实现,它允许您定义要在单元格中呈现的 HTML.如果您需要一个可以响应事件的按钮,则需要定义自定义单元格来处理浏览器事件(例如单击事件).Google 在其关于自定义单元格的文档中做得很好,解释了如何去做.

AbstractCell is an implementation of the Cell interface which allows you to define the HTML to render within the cell. If you need a button which can respond to events you'll need to define your custom cell to handle browser events (such as the click event). Google does a good job in their documentation on custom cells explaining how you can go about doing that.

查看此链接:http://www.gwtproject.org/doc/latest/DevGuideUiCustomCells.html

相关文章