自定义 gxt Cell 可能需要 Widget

2024-08-24Java开发问题
1

本文介绍了自定义 gxt Cell 可能需要 Widget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

这篇关于自定义 gxt Cell 可能需要 Widget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13