如何使TreeViewer单元格的部分变为粗体? [英] How do I make part of a TreeViewer cell bold?
问题描述
我当前要基于JFace TreeViewer
编写Eclipse编辑器.我在TreeViewer
上添加了CellLabelProvider
.如果直接在CellLabelProvider
的update
方法中将单元格的字体设置为粗体,则标签显示为粗体.
I currently want to write an Eclipse editor based on a JFace TreeViewer
. I added a CellLabelProvider
to the TreeViewer
. If I set the font of a cell with directly in the update
method of the CellLabelProvider
to a bold font the label is shown bold.
但是我只希望标签的一部分显示为粗体.因此,我将StyleRange
应用于单元格.在'StyleRange'中选择的颜色效果很好,但是将StyleRange
的字体设置为粗体似乎无效.
But I want only part of the label to be shown as bold. So I apply StyleRange
s to the cell. Selected colors in the 'StyleRange's work perfectly, but setting the font of a StyleRange
to a bold one, does not seem to work.
为什么会这样,我该如何解决?
Why is that and how do I fix it?
推荐答案
您可能需要使用基于StyledCellLabelProvider
的标签提供程序.
You probably need to use a label provider based on StyledCellLabelProvider
.
DelegatingStyledCellLabelProvider
最易于使用,因为您只需要提供实现DelegatingStyledCellLabelProvider.IStyledLabelProvider
的标签提供程序即可.关键方法是
DelegatingStyledCellLabelProvider
is easiest to use because you only need to provide a label provider implementing DelegatingStyledCellLabelProvider.IStyledLabelProvider
. The key method in this is
public StyledString getStyledText(Object element);
,您只需为每个对象返回StyledString
.
which lets you just return a StyledString
for each object.
这篇关于如何使TreeViewer单元格的部分变为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!