简体   繁体   English

GWT-树-TreeItem中仅粗体的父项

[英]GWT - Tree - Bold only parent item in a TreeItem

I would like in a Tree to bold parent item only, and keep the sub-items normal size. 我想在树中仅将父项目加粗,并保持子项目的正常大小。

I tried to use css in this way, but it does not work: 我试图以这种方式使用css,但是它不起作用:

.gwt-Tree{
    font-weight: bold;
}

.gwt-TreeItem {
    font-weight: normal;
}

.gwt-Tree .gwt-TreeItem-selected {
    font-weight: normal;
}

Is there a way to get there? 有没有办法到达那里?

Thank you in advance 先感谢您

Edited- Java code: 编辑-Java代码:

String[] composers = new String[]{"Item 1","Item 2","Item 3"};

Resources treeResource = GWT.create(TreeResources.class); 

Tree staticTree = new Tree(treeResource);

TreeItem item1 = staticTree.addTextItem(composers[0]);          

TreeItem item2 = staticTree.addTextItem(composers[1]);

// add sub items
addItemSection(item1, "item 1 - 1",new String[]{});
addItemSection(item1, "item 1 - 2", new String[]{});

addItemSection(item2, "item 2 - 1",new String[]{});
addItemSection(item2, "item 2 - 2", new String[]{});
addItemSection(item2, "item 2 - 3", new String[]{});

TreeItem item = new TreeItem();
item1.addItem(item);
item2.addItem(item);

Tree t = new Tree();
t.addItem(item1);
t.addItem(item2);

private void addItemSection(TreeItem parent, String label, String[] composerWorks) 
{
   TreeItem section = parent.addTextItem(label);        

   for (String work : composerWorks) {
    section.addTextItem(work);
   }
}

The result: 结果:

Item 1 项目1
Item 1 - 1 项目1-1
Item 1 - 2 项目1-2

Item 2 项目2
Item 2 - 1 项目2-1
Item 2 - 2 项目2-2
Item 2 - 3 项目2-3

But in my case everything is in bold :/ 但就我而言,一切都以粗体显示:/

It's been a while for me but I remember you can add HTML tags for CSS styles in your java code to the tree objects. 对我来说已经有一段时间了,但是我记得您可以在Java代码中为树对象添加CSS样式的HTML标签。

See: http://blog.francoismaillet.com/?p=68 参见: http : //blog.francoismaillet.com/?p=68

One way to do it is like this: 一种方法是这样的:

.root {font-size: 12; font-weight: bold;}
.leaf {font-size: 12; font-weight: normal;}

TreeItem root = new TreeItem("MyRootDescr");
root.addStyleName("root");

TreeItem item = new TreeItem("MyLeafDescr");
item.addStyleName("leaf");

This may seem inelegant, but it works. 这看似微不足道,但确实可行。 After setting the parent item style iterate through children and set their style to the basic style (in your case plain text). 设置父项样式后,将遍历子项并将其样式设置为基本样式(在您的情况下为纯文本)。

in your CSS file: 在您的CSS文件中:

.styleTreeItemParent {
 font-weight: bold;
}

.styleTreeItemChild {
 font-weight: normal;
}

in your GWT class: add method styleParent with parent treeItem as argument. 在您的GWT类中:添加带有父treeItem作为参数的styleParent方法。

 private void styleParent(TreeItem item) {
    int nC=item.getChildCount();
        item.setStyleName("styleTreeItemParent");

        for(int i=0;i<nC;i++) {
            item.getChild(i).setStyleName("styleTreeItemChild");
        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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