capint
8/28/2016 - 11:13 AM

Eclipse >> SWT >> Tree

Eclipse >> SWT >> Tree

Menu menu = new Menu(tree);
MenuItem menuItem = new MenuItem(menu, SWT.NONE);
menuItem.setText("Print Element");
menuItem.addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent event) {
        System.out.println(tree.getSelection()[0].getText());
    }
});

tree.setMenu(menu);
 
Source: http://www.vogella.com/tutorials/SWT/article.html#swt_tree
final Tree tree = new Tree(shell, SWT.V_SCROLL);
for (int i=0; i<5;i++) {
  TreeItem item = new TreeItem(tree, SWT.NONE);
  item.setText(String.valueOf(i));
  for (int j=0; j<3;j++) {
    TreeItem subItem = new TreeItem(item, SWT.NONE);
    subItem.setText(String.valueOf(i) + " " + String.valueOf(j));
  }
}
tree.pack();

Source: http://www.vogella.com/tutorials/SWT/article.html#swt_tree