【问题标题】:Swt StyledText lose caret while adapte it into swt Tree componentSwt StyledText 在将其改编为 swt Tree 组件时丢失了插入符号
【发布时间】:2020-06-16 08:58:37
【问题描述】:

我的目的是在 SWT 应用程序中为 Tree 组合添加样式文本。 没问题,我可以添加和使用,但是缺少 styledText 的插入符号。

经过调查,应该是Tree / Table的原因。两者都不见了。 但它适用于 Canvas。

display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());

final Composite baseComposite = new Composite(shell, SWT.NONE);
baseComposite.setLayout(new GridLayout());
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

final Tree tree = new Tree(baseComposite, SWT.BORDER | SWT.FULL_SELECTION);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

StyledText styledText = new StyledText(tree, SWT.BORDER );

这是平台限制还是Tree和StyledText的冲突?

【问题讨论】:

    标签: eclipse treeview swt editor jface


    【解决方案1】:

    Tree 的 Javadoc 说:

    请注意,虽然这个类是 Composite 的子类,但它不是 通常将 Control 子级添加到它是有意义的,或者设置一个布局 它,除非实现像单元格编辑器之类的东西。

    因此,实际上并不支持将StyledText 添加为直接子代。

    【讨论】:

    • 非常感谢您的回答。是的,我采用的方式是单元格编辑器。在树中,我使用 TreeEditor -> CellEditor -> CompositeContainer -> StyledText 来显示富格式文本。除了这个令人讨厌的 Caret 问题外,一切看起来都很好。通过调试,插入符号被初始化并且可以工作但不可见。真的有线。顺便说一句,在 Canvas 中正常工作。
    • 我认为 Tree 在插入符号显示上无法与 StyledText 一起使用。我认为 StyledText 覆盖了“句柄”,但 StyledText Caret 绘图依赖于“句柄”。这应该是一个兼容性错误。
    猜你喜欢
    • 2012-10-20
    • 2013-09-01
    • 1970-01-01
    • 2014-11-30
    • 2013-06-08
    • 2013-11-14
    • 1970-01-01
    • 2011-09-13
    • 2011-05-29
    相关资源
    最近更新 更多