我想知道是否有人知道是否可以删除出现在 GWT 树中根项旁边的“+”号?我没有看到处理它的 CSS 规则。可以用 GIF 代替 + 号吗?
(出于说明目的改编自以下 GWT 手册的代码)
TreeItem root = new TreeItem("root");//希望删除此项旁边的 + 号
root.addItem("item0");
root.addItem("item1");
root.addItem("item2");
root.setState(true, true);
// Add a CheckBox to the tree
TreeItem item = new TreeItem(new CheckBox("item3"));
root.addItem(item);
Tree t = new Tree();
t.addItem(root);
// Add it to the root panel.
RootPanel.get().add(t);
最佳答案
CSS 样式根本不适用于此。相反,它需要为树使用不同的构造函数。如果将 spacer.png 设置为 1x1 透明 PNG,它将删除 + 号。这是我使用的完整代码。
正确的做法是:
public interface MyResources extends ClientBundle {
public static final MyResources INSTANCE = GWT.create(MyResources.class);
@Source("spacer.png")
public ImageResource leaf();
}
public class TreeImagesExample implements Tree.Resources
{
@Override
public ImageResource treeClosed() {
// TODO Auto-generated method stub
return MyResources.INSTANCE.leaf();
}
@Override
public ImageResource treeLeaf() {
// TODO Auto-generated method stub
return MyResources.INSTANCE.leaf();
}
@Override
public ImageResource treeOpen() {
// TODO Auto-generated method stub
return MyResources.INSTANCE.leaf();
}
}
Main Function:
TreeImagesExample tx= new TreeImagesExample();
Tree t = new Tree(tx);
t.addItem(root);
为了使其正常工作,当然,我们还需要一个 SelectionHandler,以便我们可以在树项上注册树点击,而不是(现在不存在)+ 符号。
关于css - 删除 GWT 树的根项旁边的 +(加号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3543666/