gpt4 book ai didi

java - 鼠标悬停时如何在 Tapestry 5.3.6 调色板组件中显示选项文本的工具提示(标题)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:28:45 26 4
gpt4 key购买 nike

Tapestry 5.3.6 是否可以在palette 组件中显示tooltip(title) 如果选项文本太长无法显示?我对选项文本几乎相同但最后不可见的字符不同的情况很感兴趣。

最佳答案

您只需要添加自定义属性(title) 来选择模型选项。为此,您需要添加自己的 OptionModel 实现:

public class CustomOptionModel implements OptionModel {
private final String label;
private final Object value;
private final Map<String, String> attributes;

public CustomOptionModel(final String label,
final Object value,
final String tooltip) {
this.label = label;
this.value = value;

if (tooltip != null) {
attributes = new HashMap<String, String>();
attributes.put("title", tooltip);
} else {
attributes = null;
}
}

public String getLabel() {
return label;
}

public boolean isDisabled() {
return false;
}

public Map<String, String> getAttributes() {
return attributes;
}

public Object getValue() {
return value;
}
}

最后一件事是将选择的模型附加到调色板:

public SelectModel getMySelectModel() {
final List<OptionModel> options = new ArrayList<OptionModel>();
options.add(new CustomOptionModel("First", 1, "First Item"));
options.add(new CustomOptionModel("Second", 2, "Second Item"));
options.add(new CustomOptionModel("Third", 3, "Third Item"));
return new SelectModelImpl(null, options);
}

关于java - 鼠标悬停时如何在 Tapestry 5.3.6 调色板组件中显示选项文本的工具提示(标题)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17550859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com