问题描述
- swt tree的获取item值的问题
-
// 获取JsonTree对象遍历Tree控件
public static void getChild(Tree tree, JsonTree jTree)
{final TreeItem item = new TreeItem(tree, SWT.None); String itemText = jTree.getId(); String path = (jTree.getPid() == "/" ? jTree.getPid(): jTree.getPid() + "/") + jTree.getId(); String [] strings ={jTree.getId(), path}; if (!"/".equals(itemText)) { item.setText(strings); } if (jTree.isChild) { List<JsonTree> jsonTree = jTree.getList(); if (null != jsonTree && !jsonTree.isEmpty()) { for (JsonTree childData : jsonTree) { getChild(item, childData); } } } } // 获取JsonTree对象遍历TreeItem控件 private static void getChild(TreeItem treeItem, JsonTree jTree) { final TreeItem item = new TreeItem(treeItem, SWT.None); String itemText = jTree.getId(); String path = (jTree.getPid() == "/" ? jTree.getPid(): jTree.getPid() + "/") + jTree.getId(); String [] strings ={jTree.getId(), path}; if (!"/".equals(itemText)) { item.setText(strings); } if (jTree.isChild) { List<JsonTree> jsonTree = jTree.getList(); if (null != jsonTree && !jsonTree.isEmpty()) { for (JsonTree childData : jsonTree) { getChild(item, childData); } } }
tree.addSelectionListener(new SelectionListener()
{public void widgetSelected(SelectionEvent e) { TreeItem[] selection = tree.getSelection(); String text = selection[0].getText(1); System.out.println("========"+text); } public void widgetDefaultSelected(SelectionEvent e) { } });
//我在向TreeItem中set值,为一个数组,遍历tree时打印可以看到有item.getText(1)的值,但是在点击tree触发事件时为什么得不到item.getText(1)的值?
时间: 2024-09-29 13:16:11