List of usage examples for org.eclipse.swt.widgets Composite setLayout
public void setLayout(Layout layout)
From source file:FormLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);/*from w ww.jav a 2s .c om*/ Button one = new Button(shell, SWT.PUSH); one.setText("One"); FormData data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(50, -5); one.setLayoutData(data); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; composite.setLayout(gridLayout); Button two = new Button(composite, SWT.PUSH); two.setText("two"); GridData gridData = new GridData(GridData.FILL_BOTH); two.setLayoutData(gridData); Button three = new Button(composite, SWT.PUSH); three.setText("three"); gridData = new GridData(GridData.FILL_BOTH); three.setLayoutData(gridData); Button four = new Button(composite, SWT.PUSH); four.setText("four"); gridData = new GridData(GridData.FILL_BOTH); four.setLayoutData(gridData); data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(one, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(100, -5); composite.setLayoutData(data); Button five = new Button(shell, SWT.PUSH); five.setText("five"); data = new FormData(); data.top = new FormAttachment(one, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);/*from w ww . j av a 2s .c om*/ Button one = new Button(shell, SWT.PUSH); one.setText("One"); FormData data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(50, -5); one.setLayoutData(data); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 20; gridLayout.marginWidth = 20; composite.setLayout(gridLayout); Button two = new Button(composite, SWT.PUSH); two.setText("two"); GridData gridData = new GridData(GridData.FILL_BOTH); two.setLayoutData(gridData); Button three = new Button(composite, SWT.PUSH); three.setText("three"); gridData = new GridData(GridData.FILL_HORIZONTAL); three.setLayoutData(gridData); Button four = new Button(composite, SWT.PUSH); four.setText("four"); gridData = new GridData(GridData.FILL_BOTH); four.setLayoutData(gridData); data = new FormData(); data.top = new FormAttachment(0, 15); data.left = new FormAttachment(one, 25); data.bottom = new FormAttachment(50, -15); data.right = new FormAttachment(100, -25); composite.setLayoutData(data); Button five = new Button(shell, SWT.PUSH); five.setText("five"); data = new FormData(); data.top = new FormAttachment(one, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet249.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 249"); Rectangle clientArea = shell.getClientArea(); shell.setBounds(clientArea.x + 10, clientArea.y + 10, 300, 200); // create the composite that the pages will share final Composite contentPanel = new Composite(shell, SWT.BORDER); contentPanel.setBounds(clientArea.x + 100, clientArea.y + 10, 190, 90); final StackLayout layout = new StackLayout(); contentPanel.setLayout(layout); // create the first page's content final Composite page0 = new Composite(contentPanel, SWT.NONE); page0.setLayout(new RowLayout()); Label label = new Label(page0, SWT.NONE); label.setText("Label on page 1"); label.pack();//w w w .ja v a 2 s .c o m // create the second page's content final Composite page1 = new Composite(contentPanel, SWT.NONE); page1.setLayout(new RowLayout()); Button button = new Button(page1, SWT.NONE); button.setText("Button on page 2"); button.pack(); // create the button that will switch between the pages Button pageButton = new Button(shell, SWT.PUSH); pageButton.setText("Push"); pageButton.setBounds(clientArea.x + 10, clientArea.y + 10, 80, 25); pageButton.addListener(SWT.Selection, event -> { pageNum = ++pageNum % 2; layout.topControl = pageNum == 0 ? page0 : page1; contentPanel.layout(); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ExpandBarControlsAdding.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = new Image(display, "yourFile.gif"); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;/*from w w w .j a va 2 s. c o m*/ composite.setLayout(layout); Button button = new Button(composite, SWT.PUSH); button.setText("SWT.PUSH"); button = new Button(composite, SWT.RADIO); button.setText("SWT.RADIO"); button = new Button(composite, SWT.CHECK); button.setText("SWT.CHECK"); button = new Button(composite, SWT.TOGGLE); button.setText("SWT.TOGGLE"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); item0.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet338.java
public static void main(String[] args) { Display display = new Display(); Shell parentShell = new Shell(display); parentShell.setText("Snippet 338"); parentShell.setBounds(10, 10, 100, 100); parentShell.open();// w w w . j a va2s . co m Shell childShell = new Shell(parentShell); childShell.setLayout(new GridLayout()); TabFolder folder = new TabFolder(childShell, SWT.NONE); folder.setLayout(new FillLayout()); TabItem tab1 = new TabItem(folder, SWT.NONE); tab1.setText("Tab &1"); new TabItem(folder, SWT.NONE).setText("Tab &2"); Composite composite = new Composite(folder, SWT.NONE); composite.setLayout(new GridLayout()); tab1.setControl(composite); Text text1 = new Text(composite, SWT.SINGLE); /* canvas represents a custom control */ final Canvas canvas = new Canvas(composite, SWT.BORDER); canvas.setLayoutData(new GridData(300, 200)); canvas.addListener(SWT.Paint, event -> { if (canvas.isFocusControl()) { event.gc.drawText( "focus is here, custom traverse keys:\n\tN: Tab next\n\tP: Tab previous\n\tR: Return\n\tE: Esc\n\tT: Tab Folder next page", 0, 0); } else { event.gc.drawString("focus is not in this control", 0, 0); } }); canvas.addListener(SWT.KeyDown, event -> { int traversal = SWT.NONE; switch (event.keyCode) { case 'n': traversal = SWT.TRAVERSE_TAB_NEXT; break; case 'p': traversal = SWT.TRAVERSE_TAB_PREVIOUS; break; case 'r': traversal = SWT.TRAVERSE_RETURN; break; case 'e': traversal = SWT.TRAVERSE_ESCAPE; break; case 't': traversal = SWT.TRAVERSE_PAGE_NEXT; break; } if (traversal != SWT.NONE) { event.doit = true; /* this will be the Traverse event's initial doit value */ canvas.traverse(traversal, event); } }); canvas.addFocusListener(focusLostAdapter(e -> canvas.redraw())); canvas.addFocusListener(focusGainedAdapter(e -> canvas.redraw())); Text text2 = new Text(composite, SWT.SINGLE); Button button = new Button(childShell, SWT.PUSH); button.setText("Default &Button"); button.addListener(SWT.Selection, event -> System.out.println("Default button selected")); childShell.setDefaultButton(button); Listener printTraverseListener = event -> { StringBuilder buffer = new StringBuilder("Traverse "); buffer.append(event.widget); buffer.append(" type="); switch (event.detail) { case SWT.TRAVERSE_ARROW_NEXT: buffer.append("TRAVERSE_ARROW_NEXT"); break; case SWT.TRAVERSE_ARROW_PREVIOUS: buffer.append("TRAVERSE_ARROW_NEXT"); break; case SWT.TRAVERSE_ESCAPE: buffer.append("TRAVERSE_ESCAPE"); break; case SWT.TRAVERSE_MNEMONIC: buffer.append("TRAVERSE_MNEMONIC"); break; case SWT.TRAVERSE_PAGE_NEXT: buffer.append("TRAVERSE_PAGE_NEXT"); break; case SWT.TRAVERSE_PAGE_PREVIOUS: buffer.append("TRAVERSE_PAGE_PREVIOUS"); break; case SWT.TRAVERSE_RETURN: buffer.append("TRAVERSE_RETURN"); break; case SWT.TRAVERSE_TAB_NEXT: buffer.append("TRAVERSE_TAB_NEXT"); break; case SWT.TRAVERSE_TAB_PREVIOUS: buffer.append("TRAVERSE_TAB_PREVIOUS"); break; } buffer.append(" doit=" + event.doit); buffer.append(" keycode=" + event.keyCode); buffer.append(" char=" + event.character); buffer.append(" stateMask=" + event.stateMask); System.out.println(buffer.toString()); }; childShell.addListener(SWT.Traverse, printTraverseListener); folder.addListener(SWT.Traverse, printTraverseListener); composite.addListener(SWT.Traverse, printTraverseListener); canvas.addListener(SWT.Traverse, printTraverseListener); button.addListener(SWT.Traverse, printTraverseListener); text1.addListener(SWT.Traverse, printTraverseListener); text2.addListener(SWT.Traverse, printTraverseListener); childShell.pack(); childShell.open(); text1.setFocus(); while (!parentShell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ExpandBarIconAddingSystem.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = new Image(display, "yourFile.gif"); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;/*w w w. j a v a 2 s .co m*/ composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_QUESTION"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); item0.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet336.java
public static void main(String[] args) { display = new Display(); shell = new Shell(display); shell.setText("Snippet 336"); shell.setLayout(new GridLayout()); TabFolder folder = new TabFolder(shell, SWT.NONE); folder.setLayoutData(new GridData(GridData.FILL_BOTH)); //Progress tab TabItem item = new TabItem(folder, SWT.NONE); item.setText("Progress"); Composite composite = new Composite(folder, SWT.NONE); composite.setLayout(new GridLayout()); item.setControl(composite);/*from w w w .j a v a2s. com*/ Listener listener = event -> { Button button = (Button) event.widget; if (!button.getSelection()) return; TaskItem item1 = getTaskBarItem(); if (item1 != null) { int state = ((Integer) button.getData()).intValue(); item1.setProgressState(state); } }; Group group = new Group(composite, SWT.NONE); group.setText("State"); group.setLayout(new GridLayout()); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button button; String[] stateLabels = { "SWT.DEFAULT", "SWT.INDETERMINATE", "SWT.NORMAL", "SWT.ERROR", "SWT.PAUSED" }; int[] states = { SWT.DEFAULT, SWT.INDETERMINATE, SWT.NORMAL, SWT.ERROR, SWT.PAUSED }; for (int i = 0; i < states.length; i++) { button = new Button(group, SWT.RADIO); button.setText(stateLabels[i]); button.setData(Integer.valueOf(states[i])); button.addListener(SWT.Selection, listener); if (i == 0) button.setSelection(true); } group = new Group(composite, SWT.NONE); group.setText("Value"); group.setLayout(new GridLayout(2, false)); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Label label = new Label(group, SWT.NONE); label.setText("Progress"); final Scale scale = new Scale(group, SWT.NONE); scale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); scale.addListener(SWT.Selection, event -> { TaskItem item1 = getTaskBarItem(); if (item1 != null) item1.setProgress(scale.getSelection()); }); //Overlay text tab item = new TabItem(folder, SWT.NONE); item.setText("Text"); composite = new Composite(folder, SWT.NONE); composite.setLayout(new GridLayout()); item.setControl(composite); group = new Group(composite, SWT.NONE); group.setText("Enter a short text:"); group.setLayout(new GridLayout(2, false)); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Text text = new Text(group, SWT.BORDER | SWT.SINGLE); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; text.setLayoutData(data); button = new Button(group, SWT.PUSH); button.setText("Set"); button.addListener(SWT.Selection, event -> { TaskItem item1 = getTaskBarItem(); if (item1 != null) item1.setOverlayText(text.getText()); }); button = new Button(group, SWT.PUSH); button.setText("Clear"); button.addListener(SWT.Selection, event -> { text.setText(""); TaskItem item1 = getTaskBarItem(); if (item1 != null) item1.setOverlayText(""); }); //Overlay image tab item = new TabItem(folder, SWT.NONE); item.setText("Image"); composite = new Composite(folder, SWT.NONE); composite.setLayout(new GridLayout()); item.setControl(composite); Listener listener3 = event -> { Button button1 = (Button) event.widget; if (!button1.getSelection()) return; TaskItem item1 = getTaskBarItem(); if (item1 != null) { String text1 = button1.getText(); Image image = null; if (!text1.equals("NONE")) image = new Image(display, Snippet336.class.getResourceAsStream(text1)); Image oldImage = item1.getOverlayImage(); item1.setOverlayImage(image); if (oldImage != null) oldImage.dispose(); } }; group = new Group(composite, SWT.NONE); group.setText("Images"); group.setLayout(new GridLayout()); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); button = new Button(group, SWT.RADIO); button.setText("NONE"); button.addListener(SWT.Selection, listener3); button.setSelection(true); String[] images = { "eclipse.png", "pause.gif", "run.gif", "warning.gif" }; for (int i = 0; i < images.length; i++) { button = new Button(group, SWT.RADIO); button.setText(images[i]); button.addListener(SWT.Selection, listener3); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(); layout.numColumns = 3;// w w w .j a v a 2s . c o m layout.makeColumnsEqualWidth = true; shell.setLayout(layout); // Create the big button in the upper left GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 200; Button one = new Button(shell, SWT.PUSH); one.setText("one"); one.setLayoutData(data); // Create a composite to hold the three buttons in the upper right Composite composite = new Composite(shell, SWT.NONE); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; composite.setLayoutData(data); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 15; composite.setLayout(layout); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet234.java
public static void main(String[] args) { int rowCount = 40; int columnCount = 15; final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 234"); shell.setLayout(new FillLayout()); Composite parent = new Composite(shell, SWT.BORDER); GridLayout layout = new GridLayout(2, false); layout.marginWidth = layout.marginHeight = layout.horizontalSpacing = 0; parent.setLayout(layout); final Table leftTable = new Table(parent, SWT.MULTI | SWT.FULL_SELECTION); leftTable.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true)); leftTable.setHeaderVisible(true);//from w w w .ja v a 2s . co m final Table rightTable = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); rightTable.setHeaderVisible(true); GridData table2Data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2); rightTable.setLayoutData(table2Data); // Create columns TableColumn column1 = new TableColumn(leftTable, SWT.NONE); column1.setText("Name"); column1.setWidth(150); for (int i = 0; i < columnCount; i++) { TableColumn column = new TableColumn(rightTable, SWT.NONE); column.setText("Value " + i); column.setWidth(200); } // Create rows for (int i = 0; i < rowCount; i++) { TableItem item = new TableItem(leftTable, SWT.NONE); item.setText("item " + i); item = new TableItem(rightTable, SWT.NONE); for (int j = 0; j < columnCount; j++) { item.setText(j, "Item " + i + " value @ " + j); } } // Make selection the same in both tables leftTable.addListener(SWT.Selection, event -> rightTable.setSelection(leftTable.getSelectionIndices())); rightTable.addListener(SWT.Selection, event -> leftTable.setSelection(rightTable.getSelectionIndices())); // On Windows, the selection is gray if the table does not have focus. // To make both tables appear in focus, draw the selection background here. // This part only works on version 3.2 or later. Listener eraseListener = event -> { event.detail &= ~SWT.HOT; if ((event.detail & SWT.SELECTED) != 0) { GC gc = event.gc; Rectangle rect = event.getBounds(); gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT)); gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION)); gc.fillRectangle(rect); event.detail &= ~SWT.SELECTED; } }; leftTable.addListener(SWT.EraseItem, eraseListener); rightTable.addListener(SWT.EraseItem, eraseListener); // Make vertical scrollbars scroll together ScrollBar vBarLeft = leftTable.getVerticalBar(); vBarLeft.addListener(SWT.Selection, event -> rightTable.setTopIndex(leftTable.getTopIndex())); ScrollBar vBarRight = rightTable.getVerticalBar(); vBarRight.addListener(SWT.Selection, event -> leftTable.setTopIndex(rightTable.getTopIndex())); // Horizontal bar on second table takes up a little extra space. // To keep vertical scroll bars in sink, force table1 to end above // horizontal scrollbar ScrollBar hBarRight = rightTable.getHorizontalBar(); Label spacer = new Label(parent, SWT.NONE); GridData spacerData = new GridData(); spacerData.heightHint = hBarRight.getSize().y; spacer.setVisible(false); parent.setBackground(leftTable.getBackground()); shell.setSize(600, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(); layout.numColumns = 3;/* w ww . j av a 2 s . c o m*/ layout.makeColumnsEqualWidth = true; shell.setLayout(layout); // Create the big button in the upper left GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 200; Button one = new Button(shell, SWT.PUSH); one.setText("one"); one.setLayoutData(data); // Create a composite to hold the three buttons in the upper right Composite composite = new Composite(shell, SWT.NONE); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; composite.setLayoutData(data); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 15; composite.setLayout(layout); // Create button "two" data = new GridData(GridData.FILL_BOTH); Button two = new Button(composite, SWT.PUSH); two.setText("two"); two.setLayoutData(data); // Create button "three" data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); Button three = new Button(composite, SWT.PUSH); three.setText("three"); three.setLayoutData(data); // Create button "four" data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); Button four = new Button(composite, SWT.PUSH); four.setText("four"); four.setLayoutData(data); // Create the long button across the bottom data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; data.horizontalSpan = 3; data.heightHint = 150; Button five = new Button(shell, SWT.PUSH); five.setText("five"); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }