简体   繁体   中英

how to add tooltip to the label which is then added to the celltable column?

I have a celltable. I want to add multiple labels with some tooltip assigned to each in one column of a celltable. what i have tried so far -

TextColumn<C> detailsColumn = new TextColumn<C>() {
  @Override
  public String getValue(C c) {
    List<String[]> cList = c.getChngd();
    if (cList == null || cList.size() == 0) {
      return null;
    }
    Label lbl;
    HorizontalPanel hpanel=new HorizontalPanel();
    for (Iterator<String[]> itr =List.iterator(); itr.hasNext();) {
      String[] detail = itr.next();
      lbl=new Label();
      lbl.setText(detail[0]);
      lbl.addMouseOverHandler(new MouseOverHandler() {
        @Override 
        public void onMouseOver(MouseOverEvent event) {
          Widget source = (Widget)event.getSource();
          source.setTitle("tooltip");
        }
      });
      hpanel.add(lbl);
    }
    return hpanel.getElement().getInnerText();
  }
}; 

Its not working. Any solutions for the same?

I'd move the tooltip logic into the Cell , rather than into the getCell() method of the Column , which is used only to retrieve the underlying data the cell is going to render.

If you want a simple title-based cell, the following should work. It creates a text cell with the data value wrapped in a div with a title.

public class TooltipTextCell extends TextCell {
  public interface Template extends SafeHtmlTemplates {
    @Template("<div title=\"{1}\" />{0}</div>")
    SafeHtml label(SafeHtml text, String title);
  }
  private static Template template;

  public TooltipTextCell() {
    super();
    if (template == null) {
      template = GWT.create(Template.class);
    }
  }

  @Override
  public void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {
    if (value != null) {
      sb.append(template.label(value, value.asString()));
    }
  }
}

If you want to create a column in which each cell can contain multiple of such TooltipTextCell , you have to use a CompositeCell .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM