List of usage examples for org.eclipse.swt.widgets Tree setHeaderVisible
public void setHeaderVisible(boolean value)
true
, and marks it invisible otherwise. From source file:CreateTreeWithcolumns.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Tree tree = new Tree(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); tree.setHeaderVisible(true); TreeColumn column1 = new TreeColumn(tree, SWT.LEFT); column1.setText("Column 1"); column1.setWidth(200);/*from w w w .j a v a2 s . co m*/ TreeColumn column2 = new TreeColumn(tree, SWT.CENTER); column2.setText("Column 2"); column2.setWidth(200); TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT); column3.setText("Column 3"); column3.setWidth(200); for (int i = 0; i < 4; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(new String[] { "item " + i, "abc", "defghi" }); for (int j = 0; j < 4; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText(new String[] { "subitem " + j, "jklmnop", "qrs" }); for (int k = 0; k < 4; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setText(new String[] { "subsubitem " + k, "tuv", "wxyz" }); } } } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet170.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 170"); shell.setLayout(new FillLayout()); Tree tree = new Tree(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); tree.setHeaderVisible(true); TreeColumn column1 = new TreeColumn(tree, SWT.LEFT); column1.setText("Column 1"); column1.setWidth(200);/*from w ww . j av a 2 s.c om*/ TreeColumn column2 = new TreeColumn(tree, SWT.CENTER); column2.setText("Column 2"); column2.setWidth(200); TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT); column3.setText("Column 3"); column3.setWidth(200); for (int i = 0; i < 4; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(new String[] { "item " + i, "abc", "defghi" }); for (int j = 0; j < 4; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText(new String[] { "subitem " + j, "jklmnop", "qrs" }); for (int k = 0; k < 4; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setText(new String[] { "subsubitem " + k, "tuv", "wxyz" }); } } } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet266.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 266"); shell.setLayout(new GridLayout(2, true)); TabFolder tabFolder = new TabFolder(shell, SWT.NONE); tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText("Widget"); Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new GridLayout()); Tree tree = new Tree(composite, SWT.BORDER); item.setControl(composite);//from w w w . j a v a 2 s. c o m tree.setHeaderVisible(true); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); TreeColumn column1 = new TreeColumn(tree, SWT.NONE); column1.setText("Standard"); TreeColumn column2 = new TreeColumn(tree, SWT.NONE); column2.setText("Widget"); TreeItem branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Efficient", "Portable" }); TreeItem leaf = new TreeItem(branch, SWT.NONE); leaf.setText(new String[] { "Cross", "Platform" }); branch.setExpanded(true); branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Native", "Controls" }); leaf = new TreeItem(branch, SWT.NONE); leaf.setText(new String[] { "Cross", "Platform" }); branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Cross", "Platform" }); column1.pack(); column2.pack(); item = new TabItem(tabFolder, SWT.NONE); item.setText("Toolkit"); Button button = new Button(shell, SWT.CHECK); button.setText("Totally"); button.setSelection(true); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); button = new Button(shell, SWT.PUSH); button.setText("Awesome"); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet232.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("Show results as a bar chart in Tree"); final Tree tree = new Tree(shell, SWT.BORDER); tree.setHeaderVisible(true); tree.setLinesVisible(true);/*from ww w. j av a 2 s . c o m*/ TreeColumn column1 = new TreeColumn(tree, SWT.NONE); column1.setText("Bug Status"); column1.setWidth(100); final TreeColumn column2 = new TreeColumn(tree, SWT.NONE); column2.setText("Percent"); column2.setWidth(200); String[] states = new String[] { "Resolved", "New", "Won't Fix", "Invalid" }; String[] teams = new String[] { "UI", "SWT", "OSGI" }; for (int i = 0; i < teams.length; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(teams[i]); for (int j = 0; j < states.length; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText(states[j]); } } /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be * as efficient as possible. */ tree.addListener(SWT.PaintItem, new Listener() { int[] percents = new int[] { 50, 30, 5, 15 }; @Override public void handleEvent(Event event) { if (event.index == 1) { TreeItem item = (TreeItem) event.item; TreeItem parent = item.getParentItem(); if (parent != null) { GC gc = event.gc; int index = parent.indexOf(item); int percent = percents[index]; Color foreground = gc.getForeground(); Color background = gc.getBackground(); gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); int width = (column2.getWidth() - 1) * percent / 100; gc.fillGradientRectangle(event.x, event.y, width, event.height, true); Rectangle rect2 = new Rectangle(event.x, event.y, width - 1, event.height - 1); gc.drawRectangle(rect2); gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); String text = percent + "%"; Point size = event.gc.textExtent(text); int offset = Math.max(0, (event.height - size.y) / 2); gc.drawText(text, event.x + 2, event.y + offset, true); gc.setForeground(background); gc.setBackground(foreground); } } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TreeTableBarChart.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("Show results as a bar chart in Tree"); final Tree tree = new Tree(shell, SWT.BORDER); tree.setHeaderVisible(true); tree.setLinesVisible(true);//from w w w.j a v a 2s .c om TreeColumn column1 = new TreeColumn(tree, SWT.NONE); column1.setText("Bug Status"); column1.setWidth(100); final TreeColumn column2 = new TreeColumn(tree, SWT.NONE); column2.setText("Percent"); column2.setWidth(200); String[] states = new String[] { "Resolved", "New", "Won't Fix", "Invalid" }; String[] teams = new String[] { "UI", "SWT", "OSGI" }; for (int i = 0; i < teams.length; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(teams[i]); for (int j = 0; j < states.length; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText(states[j]); } } /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be as * efficient as possible. */ tree.addListener(SWT.PaintItem, new Listener() { int[] percents = new int[] { 50, 30, 5, 15 }; public void handleEvent(Event event) { if (event.index == 1) { TreeItem item = (TreeItem) event.item; TreeItem parent = item.getParentItem(); if (parent != null) { GC gc = event.gc; int index = parent.indexOf(item); int percent = percents[index]; Color foreground = gc.getForeground(); Color background = gc.getBackground(); gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); int width = (column2.getWidth() - 1) * percent / 100; gc.fillGradientRectangle(event.x, event.y, width, event.height, true); Rectangle rect2 = new Rectangle(event.x, event.y, width - 1, event.height - 1); gc.drawRectangle(rect2); gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); String text = percent + "%"; Point size = event.gc.textExtent(text); int offset = Math.max(0, (event.height - size.y) / 2); gc.drawText(text, event.x + 2, event.y + offset, true); gc.setForeground(background); gc.setBackground(foreground); } } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet240.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Text spans two columns in a TreeItem"); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION); tree.setHeaderVisible(true); int columnCount = 4; for (int i = 0; i < columnCount; i++) { TreeColumn column = new TreeColumn(tree, SWT.NONE); column.setText("Column " + i); }//w w w . jav a2s .c o m int itemCount = 8; for (int i = 0; i < itemCount; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(0, "item " + i + " a"); item.setText(3, "item " + i + " d"); for (int j = 0; j < 3; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText(0, "subItem " + i + "-" + j + " a"); subItem.setText(3, "subItem " + i + "-" + j + " d"); } } /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be * as efficient as possible. */ final String string = "text that spans two columns"; GC gc = new GC(tree); final Point extent = gc.stringExtent(string); gc.dispose(); final Color red = display.getSystemColor(SWT.COLOR_RED); Listener paintListener = event -> { switch (event.type) { case SWT.MeasureItem: { if (event.index == 1 || event.index == 2) { event.width = extent.x / 2; event.height = Math.max(event.height, extent.y + 2); } break; } case SWT.PaintItem: { if (event.index == 1 || event.index == 2) { int offset = 0; if (event.index == 2) { TreeColumn column1 = tree.getColumn(1); offset = column1.getWidth(); } event.gc.setForeground(red); int y = event.y + (event.height - extent.y) / 2; event.gc.drawString(string, event.x - offset, y, true); } break; } } }; tree.addListener(SWT.MeasureItem, paintListener); tree.addListener(SWT.PaintItem, paintListener); for (int i = 0; i < columnCount; i++) { tree.getColumn(i).pack(); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TreeEventMeasurePaintErase.java
public static void main(String[] args) { Display display = new Display(); final Image image = display.getSystemImage(SWT.ICON_INFORMATION); Shell shell = new Shell(display); shell.setText("Images on the right side of the TreeItem"); shell.setLayout(new FillLayout()); Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION); tree.setHeaderVisible(true); tree.setLinesVisible(true);//from w ww . j a va 2s.com int columnCount = 4; for (int i = 0; i < columnCount; i++) { TreeColumn column = new TreeColumn(tree, SWT.NONE); column.setText("Column " + i); } int itemCount = 3; for (int i = 0; i < itemCount; i++) { TreeItem item1 = new TreeItem(tree, SWT.NONE); item1.setText("item " + i); for (int c = 1; c < columnCount; c++) { item1.setText(c, "item [" + i + "-" + c + "]"); } for (int j = 0; j < itemCount; j++) { TreeItem item2 = new TreeItem(item1, SWT.NONE); item2.setText("item [" + i + " " + j + "]"); for (int c = 1; c < columnCount; c++) { item2.setText(c, "item [" + i + " " + j + "-" + c + "]"); } for (int k = 0; k < itemCount; k++) { TreeItem item3 = new TreeItem(item2, SWT.NONE); item3.setText("item [" + i + " " + j + " " + k + "]"); for (int c = 1; c < columnCount; c++) { item3.setText(c, "item [" + i + " " + j + " " + k + "-" + c + "]"); } } } } /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be as * efficient as possible. */ Listener paintListener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.MeasureItem: { Rectangle rect = image.getBounds(); event.width += rect.width; event.height = Math.max(event.height, rect.height + 2); break; } case SWT.PaintItem: { int x = event.x + event.width; Rectangle rect = image.getBounds(); int offset = Math.max(0, (event.height - rect.height) / 2); event.gc.drawImage(image, x, event.y + offset); break; } } } }; tree.addListener(SWT.MeasureItem, paintListener); tree.addListener(SWT.PaintItem, paintListener); for (int i = 0; i < columnCount; i++) { tree.getColumn(i).pack(); } shell.setSize(500, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet193.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 193"); shell.setLayout(new RowLayout(SWT.HORIZONTAL)); final Tree tree = new Tree(shell, SWT.BORDER | SWT.CHECK); tree.setLayoutData(new RowData(-1, 300)); tree.setHeaderVisible(true); TreeColumn column = new TreeColumn(tree, SWT.LEFT); column.setText("Column 0"); column = new TreeColumn(tree, SWT.CENTER); column.setText("Column 1"); column = new TreeColumn(tree, SWT.LEFT); column.setText("Column 2"); column = new TreeColumn(tree, SWT.RIGHT); column.setText("Column 3"); column = new TreeColumn(tree, SWT.CENTER); column.setText("Column 4"); for (int i = 0; i < 5; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); String[] text = new String[] { i + ":0", i + ":1", i + ":2", i + ":3", i + ":4" }; item.setText(text);/*from w ww .j a v a2 s.c o m*/ for (int j = 0; j < 5; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); text = new String[] { i + "," + j + ":0", i + "," + j + ":1", i + "," + j + ":2", i + "," + j + ":3", i + "," + j + ":4" }; subItem.setText(text); for (int k = 0; k < 5; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); text = new String[] { i + "," + j + "," + k + ":0", i + "," + j + "," + k + ":1", i + "," + j + "," + k + ":2", i + "," + j + "," + k + ":3", i + "," + j + "," + k + ":4" }; subsubItem.setText(text); } } } Listener listener = e -> System.out.println("Move " + e.widget); TreeColumn[] columns = tree.getColumns(); for (int i = 0; i < columns.length; i++) { columns[i].setWidth(100); columns[i].setMoveable(true); columns[i].addListener(SWT.Move, listener); } Button b = new Button(shell, SWT.PUSH); b.setText("invert column order"); b.addListener(SWT.Selection, e -> { int[] order = tree.getColumnOrder(); for (int i = 0; i < order.length / 2; i++) { int temp = order[i]; order[i] = order[order.length - i - 1]; order[order.length - i - 1] = temp; } tree.setColumnOrder(order); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet226.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Custom gradient selection for Tree"); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION); tree.setHeaderVisible(true); tree.setLinesVisible(true);// w w w . j ava 2 s . c o m int columnCount = 4; for (int i = 0; i < columnCount; i++) { TreeColumn column = new TreeColumn(tree, SWT.NONE); column.setText("Column " + i); } int itemCount = 3; for (int i = 0; i < itemCount; i++) { TreeItem item1 = new TreeItem(tree, SWT.NONE); item1.setText("item " + i); for (int c = 1; c < columnCount; c++) { item1.setText(c, "item [" + i + "-" + c + "]"); } for (int j = 0; j < itemCount; j++) { TreeItem item2 = new TreeItem(item1, SWT.NONE); item2.setText("item [" + i + " " + j + "]"); for (int c = 1; c < columnCount; c++) { item2.setText(c, "item [" + i + " " + j + "-" + c + "]"); } for (int k = 0; k < itemCount; k++) { TreeItem item3 = new TreeItem(item2, SWT.NONE); item3.setText("item [" + i + " " + j + " " + k + "]"); for (int c = 1; c < columnCount; c++) { item3.setText(c, "item [" + i + " " + j + " " + k + "-" + c + "]"); } } } } /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be * as efficient as possible. */ tree.addListener(SWT.EraseItem, event -> { event.detail &= ~SWT.HOT; if ((event.detail & SWT.SELECTED) != 0) { GC gc = event.gc; Rectangle area = tree.getClientArea(); /* * If you wish to paint the selection beyond the end of * last column, you must change the clipping region. */ int columnCount1 = tree.getColumnCount(); if (event.index == columnCount1 - 1 || columnCount1 == 0) { int width = area.x + area.width - event.x; if (width > 0) { Region region = new Region(); gc.getClipping(region); region.add(event.x, event.y, width, event.height); gc.setClipping(region); region.dispose(); } } gc.setAdvanced(true); if (gc.getAdvanced()) gc.setAlpha(127); Rectangle rect = event.getBounds(); Color foreground = gc.getForeground(); Color background = gc.getBackground(); gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); gc.fillGradientRectangle(0, rect.y, 500, rect.height, false); // restore colors for subsequent drawing gc.setForeground(foreground); gc.setBackground(background); event.detail &= ~SWT.SELECTED; } }); for (int i = 0; i < columnCount; i++) { tree.getColumn(i).pack(); } tree.setSelection(tree.getItem(0)); shell.setSize(500, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TreeTableGradient.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Custom gradient selection for Tree"); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION); tree.setHeaderVisible(true); tree.setLinesVisible(true);/*from ww w. j a va 2 s .c om*/ int columnCount = 4; for (int i = 0; i < columnCount; i++) { TreeColumn column = new TreeColumn(tree, SWT.NONE); column.setText("Column " + i); } int itemCount = 3; for (int i = 0; i < itemCount; i++) { TreeItem item1 = new TreeItem(tree, SWT.NONE); item1.setText("item " + i); for (int c = 1; c < columnCount; c++) { item1.setText(c, "item [" + i + "-" + c + "]"); } for (int j = 0; j < itemCount; j++) { TreeItem item2 = new TreeItem(item1, SWT.NONE); item2.setText("item [" + i + " " + j + "]"); for (int c = 1; c < columnCount; c++) { item2.setText(c, "item [" + i + " " + j + "-" + c + "]"); } for (int k = 0; k < itemCount; k++) { TreeItem item3 = new TreeItem(item2, SWT.NONE); item3.setText("item [" + i + " " + j + " " + k + "]"); for (int c = 1; c < columnCount; c++) { item3.setText(c, "item [" + i + " " + j + " " + k + "-" + c + "]"); } } } } /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be as * efficient as possible. */ tree.addListener(SWT.EraseItem, new Listener() { public void handleEvent(Event event) { if ((event.detail & SWT.SELECTED) != 0) { GC gc = event.gc; Rectangle area = tree.getClientArea(); /* * If you wish to paint the selection beyond the end of last column, * you must change the clipping region. */ int columnCount = tree.getColumnCount(); if (event.index == columnCount - 1 || columnCount == 0) { int width = area.x + area.width - event.x; if (width > 0) { Region region = new Region(); gc.getClipping(region); region.add(event.x, event.y, width, event.height); gc.setClipping(region); region.dispose(); } } gc.setAdvanced(true); if (gc.getAdvanced()) gc.setAlpha(127); Rectangle rect = event.getBounds(); Color foreground = gc.getForeground(); Color background = gc.getBackground(); gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); gc.fillGradientRectangle(0, rect.y, 500, rect.height, false); // restore colors for subsequent drawing gc.setForeground(foreground); gc.setBackground(background); event.detail &= ~SWT.SELECTED; } } }); for (int i = 0; i < columnCount; i++) { tree.getColumn(i).pack(); } tree.setSelection(tree.getItem(0)); shell.setSize(500, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }