[英]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. 我将工具提示逻辑移到
Cell
,而不是移到Column
的getCell()
方法中,该方法仅用于检索单元将要呈现的基础数据。
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.
它创建一个文本单元格,数据值包装在带有标题的div中。
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
. 如果要创建一个列,其中每个单元格可以包含多个这样的
TooltipTextCell
,则必须使用CompositeCell
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.