List of usage examples for org.eclipse.swt.widgets Tree setBounds
public void setBounds(int x, int y, int width, int height)
From source file:org.eclipse.swt.snippets.Snippet102.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 102"); Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); Rectangle clientArea = shell.getClientArea(); tree.setBounds(clientArea.x, clientArea.y, 200, 200); for (int i = 0; i < 12; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("Item " + i); }//from ww w . j a v a 2 s .co m TreeItem item = new TreeItem(tree, SWT.NONE, 1); TreeItem[] items = tree.getItems(); int index = 0; while (index < items.length && items[index] != item) index++; item.setText("*** New Item " + index + " ***"); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet220.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 220"); shell.setBounds(10, 10, 350, 200);/* w w w .java 2 s .com*/ Image xImage = new Image(display, 16, 16); GC gc = new GC(xImage); gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); gc.drawLine(1, 1, 14, 14); gc.drawLine(1, 14, 14, 1); gc.drawOval(2, 2, 11, 11); gc.dispose(); final int IMAGE_MARGIN = 2; final Tree tree = new Tree(shell, SWT.CHECK); tree.setBounds(10, 10, 300, 150); TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("root item"); for (int i = 0; i < 4; i++) { TreeItem newItem = new TreeItem(item, SWT.NONE); newItem.setText("descendent " + i); if (i % 2 == 0) newItem.setData(xImage); item.setExpanded(true); item = newItem; } /* * NOTE: MeasureItem and PaintItem are called repeatedly. Therefore it is * critical for performance that these methods be as efficient as possible. */ tree.addListener(SWT.MeasureItem, event -> { TreeItem item1 = (TreeItem) event.item; Image trailingImage = (Image) item1.getData(); if (trailingImage != null) { event.width += trailingImage.getBounds().width + IMAGE_MARGIN; } }); tree.addListener(SWT.PaintItem, event -> { TreeItem item1 = (TreeItem) event.item; Image trailingImage = (Image) item1.getData(); if (trailingImage != null) { int x = event.x + event.width + IMAGE_MARGIN; int itemHeight = tree.getItemHeight(); int imageHeight = trailingImage.getBounds().height; int y = event.y + (itemHeight - imageHeight) / 2; event.gc.drawImage(trailingImage, x, y); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } xImage.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet114.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 114"); Tree tree = new Tree(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); for (int i = 0; i < 12; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("Item " + i); }/* w ww.j a v a 2 s. com*/ Rectangle clientArea = shell.getClientArea(); tree.setBounds(clientArea.x, clientArea.y, 100, 100); tree.addListener(SWT.Selection, event -> { String string = event.detail == SWT.CHECK ? "Checked" : "Selected"; System.out.println(event.item + " " + string); }); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet90.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 90"); final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); for (int i = 0; i < 12; i++) { TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText("Item " + i); }/* w w w . j a v a2s.c o m*/ tree.addListener(SWT.MouseDown, event -> { Point point = new Point(event.x, event.y); TreeItem item = tree.getItem(point); if (item != null) { System.out.println("Mouse down: " + item); } }); Rectangle clientArea = shell.getClientArea(); tree.setBounds(clientArea.x, clientArea.y, 200, 200); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TreeSingleSelection.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("TreeExample"); Tree tree = new Tree(shell, SWT.SINGLE | SWT.BORDER); // Turn off drawing to avoid flicker tree.setRedraw(false);/* w ww . j a va 2 s . c o m*/ for (int i = 0; i < 5; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("Root Item " + i); for (int j = 0; j < 3; j++) { TreeItem child = new TreeItem(item, SWT.NONE); child.setText("Child Item " + i + " - " + j); for (int k = 0; k < 3; k++) { TreeItem grandChild = new TreeItem(child, SWT.NONE); grandChild.setText("Grandchild Item " + i + " - " + j + " - " + k); } } } tree.setRedraw(true); tree.setBounds(10, 10, 400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:TreeMultiSelection.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("TreeExample"); Tree tree = new Tree(shell, SWT.MULTI | SWT.BORDER); // Turn off drawing to avoid flicker tree.setRedraw(false);/* w w w . j a v a 2s. c om*/ for (int i = 0; i < 5; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("Root Item " + i); for (int j = 0; j < 3; j++) { TreeItem child = new TreeItem(item, SWT.NONE); child.setText("Child Item " + i + " - " + j); for (int k = 0; k < 3; k++) { TreeItem grandChild = new TreeItem(child, SWT.NONE); grandChild.setText("Grandchild Item " + i + " - " + j + " - " + k); } } } tree.setRedraw(true); tree.setBounds(10, 10, 400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet97.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 97"); final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); final Menu menu = new Menu(shell, SWT.POP_UP); tree.setMenu(menu);// w ww.j a v a 2 s . co m for (int i = 0; i < 12; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("Item " + i); } menu.addListener(SWT.Show, event -> { MenuItem[] menuItems = menu.getItems(); for (int i1 = 0; i1 < menuItems.length; i1++) { menuItems[i1].dispose(); } TreeItem[] treeItems = tree.getSelection(); for (int i2 = 0; i2 < treeItems.length; i2++) { MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(treeItems[i2].getText()); } }); Rectangle clientArea = shell.getClientArea(); tree.setBounds(clientArea.x, clientArea.y, 200, 200); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet274.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 274"); Tree tree = new Tree(shell, SWT.BORDER | SWT.CHECK); tree.addListener(SWT.Selection, event -> { if (event.detail == SWT.CHECK) { TreeItem item = (TreeItem) event.item; boolean checked = item.getChecked(); checkItems(item, checked);/* ww w .jav a2s . c o m*/ checkPath(item.getParentItem(), checked, false); } }); for (int i = 0; i < 4; i++) { TreeItem itemI = new TreeItem(tree, SWT.NONE); itemI.setText("Item " + i); for (int j = 0; j < 4; j++) { TreeItem itemJ = new TreeItem(itemI, SWT.NONE); itemJ.setText("Item " + i + " " + j); for (int k = 0; k < 4; k++) { TreeItem itemK = new TreeItem(itemJ, SWT.NONE); itemK.setText("Item " + i + " " + j + " " + k); } } } Rectangle clientArea = shell.getClientArea(); tree.setBounds(clientArea.x, clientArea.y, 200, 200); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet73.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 73"); final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); final Menu menu = new Menu(shell, SWT.POP_UP); tree.setMenu(menu);// www. j av a 2 s .co m for (int i = 0; i < 12; i++) { TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText("Item " + i); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(treeItem.getText()); } menu.addListener(SWT.Show, event -> { MenuItem[] menuItems = menu.getItems(); TreeItem[] treeItems = tree.getSelection(); for (int i = 0; i < menuItems.length; i++) { String text = menuItems[i].getText(); int index = 0; while (index < treeItems.length) { if (treeItems[index].getText().equals(text)) break; index++; } menuItems[i].setEnabled(index != treeItems.length); } }); Rectangle clientArea = shell.getClientArea(); tree.setBounds(clientArea.x, clientArea.y, 200, 200); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }