如何在 SWT/Java 中将数据附加到 TreeItem? [英] How to attach data to TreeItem in SWT/Java?

查看:38
本文介绍了如何在 SWT/Java 中将数据附加到 TreeItem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在 Java 中使用 SWT GUI 工具包.我需要将一些数据附加到 TreeItems.我以前使用过的每个工具包都有一个树项,其中包含一个原始指针或一个基础对象引用以提供基本的数据包含,但我在 SWT 的 TreeItem 中找不到.

I'm starting to use the SWT GUI toolkit in Java. I have a need to attach some data to the TreeItems. Each toolkit I've previously used had a tree item, which contained a raw pointer or a base object reference to provide basic data containment, but I cannot find one in TreeItem in SWT.

如何将数据附加到 TreeItem?

How can I attach data to the TreeItem?

推荐答案

答案是:使用纯 SWT 你不能.
Standard Widget Toolkit 只处理小部件、它们的层次结构和视觉表示.将数据绑定到小部件是构建在 SWT 之上的更高级的 JFace 框架(尤其是它的数据绑定工具)的主题.您需要一些时间来掌握它,但因此您获得了 Eclipse 平台的强大功能.它使您可以绑定模型以进行查看,即使是双向查看
(→ 对模型对象的更改会立即反映在 UI 上,反之亦然).
目前,您必须保留一个单独的项目列表,并且需要使用索引.

The answer is: with pure SWT you cant't.
The Standard Widget Toolkit only takes care of the widgets, their hierarchy and the visual representation. Binding data to widgets is topic of the more advanced JFace framework (especially it's databinding facilities) which builds on top of SWT. You need some time to master it, but therefore you gain the power of the Eclipse platform. It enables you to bind a model to view, even in both direction
(→ change to model object are immediately reflected on the UI and vice versa).
Currently, you would have to keep a seperate list of items and need to work with indices.

这篇关于如何在 SWT/Java 中将数据附加到 TreeItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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