Custom gxt Cell which may take Widget

后端 未结 2 859
花落未央
花落未央 2021-01-27 14:02

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.Safe         


        
2条回答
  •  走了就别回头了
    2021-01-27 14:25

    See here for a number of examples of AbstractCell implementations.

    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;
    
      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 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.

    See this link: http://www.gwtproject.org/doc/latest/DevGuideUiCustomCells.html

提交回复
热议问题