如何使TreeViewer单元格的部分变为粗体? [英] How do I make part of a TreeViewer cell bold?

查看:43
本文介绍了如何使TreeViewer单元格的部分变为粗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前要基于JFace TreeViewer编写Eclipse编辑器.我在TreeViewer上添加了CellLabelProvider.如果直接在CellLabelProviderupdate方法中将单元格的字体设置为粗体,则标签显示为粗体.

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 StyleRanges 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆