本文介绍了是否可以使jFace TreeViewer的特定节点为其LabelProvider支持粗体字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于TreeViewer的树,并创建了myLabelProvider,其中扩展了LabelProvider ,然后使用 viewer.setLabelProvider(new ViewLabelProvider()); ,但是所有节点仍然以普通的普通样式显示。



代码:

  class ViewLabelProvider extends LabelProvider实现ITableLabelProvider,ITableFontProvider {

public String getText(Object obj){
return obj.toString();
}

public Image getImage(Object obj){
return null;
}

public Font getFont(Object element,int columnIndex){
FontRegistry registry = new FontRegistry();
return registry.getBold(Display.getCurrent()。getSystemFont()。getFontData()[0] .getName());
}

public Image getColumnImage(Object element,int columnIndex){
return null;
}

public String getColumnText(Object element,int columnIndex){
return null;
}
}

参考文献:







任何人都可以提供一些建议?

解决方案

如果你只是使用一个列,那么让你的标签提供者实现 IFontProvider (也许 IColorProvider

  public Font getFont(Object element){
返回字体或null使用默认
}

注意:如果您创建任何字体完成后请务必妥善处理。


I'm developing a tree based on TreeViewer and created myLabelProvider which extends LabelProvider and then use viewer.setLabelProvider(new ViewLabelProvider());, but all the nodes are still displayed with normal plain style.

Code:

class ViewLabelProvider extends LabelProvider implements ITableLabelProvider, ITableFontProvider{

    public String getText(Object obj) {
        return obj.toString();
    }

    public Image getImage(Object obj) {
        return null;
    }

    public Font getFont(Object element, int columnIndex) {
        FontRegistry registry = new FontRegistry();
        return registry.getBold(Display.getCurrent().getSystemFont().getFontData()[0].getName());
    }

    public Image getColumnImage(Object element, int columnIndex) {
        return null;
    }

    public String getColumnText(Object element, int columnIndex) {
        return null;
    }
}

References:

http://www.eclipsezone.com/eclipse/forums/t95078.html
How do I make part of a TreeViewer cell bold?

Can anyone give some advice?

解决方案

If you are just using a single column then make your label provider implement IFontProvider (and perhaps IColorProvider)

public Font getFont(Object element) {
   return font or null to use default
}

Note: If you create any fonts be sure to dispose of them when your are done.

这篇关于是否可以使jFace TreeViewer的特定节点为其LabelProvider支持粗体字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 11:01