List of usage examples for org.eclipse.swt.widgets Composite setLayout
public void setLayout(Layout layout)
From source file:org.eclipse.swt.snippets.Snippet75.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 75"); shell.setLayout(new RowLayout()); Composite c1 = new Composite(shell, SWT.BORDER); c1.setLayout(new RowLayout()); Button b1 = new Button(c1, SWT.PUSH); b1.setText("B&1"); Button r1 = new Button(c1, SWT.RADIO); r1.setText("R1"); Button r2 = new Button(c1, SWT.RADIO); r2.setText("R&2"); Button r3 = new Button(c1, SWT.RADIO); r3.setText("R3"); Button b2 = new Button(c1, SWT.PUSH); b2.setText("B2"); List l1 = new List(c1, SWT.SINGLE | SWT.BORDER); l1.setItems("L1"); Button b3 = new Button(c1, SWT.PUSH); b3.setText("B&3"); Button b4 = new Button(c1, SWT.PUSH); b4.setText("B&4"); Composite c2 = new Composite(shell, SWT.BORDER); c2.setLayout(new RowLayout()); Button b5 = new Button(c2, SWT.PUSH); b5.setText("B&5"); Button b6 = new Button(c2, SWT.PUSH); b6.setText("B&6"); List l2 = new List(shell, SWT.SINGLE | SWT.BORDER); l2.setItems("L2"); ToolBar tb1 = new ToolBar(shell, SWT.FLAT | SWT.BORDER); ToolItem i1 = new ToolItem(tb1, SWT.RADIO); i1.setText("I1"); ToolItem i2 = new ToolItem(tb1, SWT.RADIO); i2.setText("I2"); Combo combo1 = new Combo(tb1, SWT.READ_ONLY | SWT.BORDER); combo1.setItems("C1"); combo1.setText("C1"); combo1.pack();//from w w w.ja v a2 s . c om ToolItem i3 = new ToolItem(tb1, SWT.SEPARATOR); i3.setWidth(combo1.getSize().x); i3.setControl(combo1); ToolItem i4 = new ToolItem(tb1, SWT.PUSH); i4.setText("I&4"); ToolItem i5 = new ToolItem(tb1, SWT.CHECK); i5.setText("I5"); Button b7 = new Button(shell, SWT.PUSH); b7.setText("B&7"); Composite c4 = new Composite(shell, SWT.BORDER); Composite c5 = new Composite(c4, SWT.BORDER); c5.setLayout(new FillLayout()); new Label(c5, SWT.NONE).setText("No"); c5.pack(); Control[] tabList1 = new Control[] { b2, b1, b3 }; c1.setTabList(tabList1); Control[] tabList2 = new Control[] { c1, b7, tb1, c4, c2, l2 }; shell.setTabList(tabList2); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet195.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true;//from ww w. ja v a2 s .co m final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data); canvas.setCurrent(); GL.createCapabilities(); canvas.addListener(SWT.Resize, event -> { Rectangle bounds = canvas.getBounds(); float fAspect = (float) bounds.width / (float) bounds.height; canvas.setCurrent(); GL.createCapabilities(); GL11.glViewport(0, 0, bounds.width, bounds.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float near = 0.5f; float bottom = -near * (float) Math.tan(45.f / 2); float left = fAspect * bottom; GL11.glFrustum(left, -left, bottom, -bottom, near, 400.f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); }); GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glClearDepth(1.0); GL11.glLineWidth(2); GL11.glEnable(GL11.GL_DEPTH_TEST); shell.setText("SWT/LWJGL Example"); shell.setSize(640, 480); shell.open(); final Runnable run = new Runnable() { int rot = 0; @Override public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); GL.createCapabilities(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClearColor(.3f, .5f, .8f, 1.0f); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -10.0f); float frot = rot; GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); rot++; GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); GL11.glColor3f(0.9f, 0.9f, 0.9f); drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); canvas.swapBuffers(); display.asyncExec(this); } } }; canvas.addListener(SWT.Paint, event -> run.run()); display.asyncExec(run); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ViewFormCreate.java
public static void main(String[] args) { Shell shell = new Shell(display); shell.setText("Look"); shell.setLayout(new GridLayout(1, false)); Button button = new Button(shell, SWT.PUSH); button.setText("New Document"); final Composite composite = new Composite(shell, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new FillLayout()); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { createViewFormHelper(composite, "Document " + (++count)); composite.layout();//from w w w . j a v a 2 s. c o m } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet282.java
public static void main(String[] args) { final Display display = new Display(); final Clipboard clipboard = new Clipboard(display); final Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setText("Snippet 282"); shell.setLayout(new GridLayout()); shell.setText("Clipboard ImageTransfer"); final Button imageButton = new Button(shell, SWT.NONE); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.minimumHeight = 400;/*from w w w.j ava 2 s . c om*/ gd.minimumWidth = 600; imageButton.setLayoutData(gd); final Text imageText = new Text(shell, SWT.BORDER); imageText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); Composite buttons = new Composite(shell, SWT.NONE); buttons.setLayout(new GridLayout(4, true)); Button button = new Button(buttons, SWT.PUSH); button.setText("Open"); button.addListener(SWT.Selection, event -> { FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setText("Open an image file or cancel"); String string = dialog.open(); if (string != null) { imageButton.setText(""); Image image = imageButton.getImage(); if (image != null) image.dispose(); image = new Image(display, string); imageButton.setImage(image); imageText.setText(string); } }); button = new Button(buttons, SWT.PUSH); button.setText("Copy"); button.addListener(SWT.Selection, event -> { Image image = imageButton.getImage(); if (image != null) { ImageTransfer imageTransfer = ImageTransfer.getInstance(); TextTransfer textTransfer = TextTransfer.getInstance(); clipboard.setContents(new Object[] { image.getImageData(), imageText.getText() }, new Transfer[] { imageTransfer, textTransfer }); } }); button = new Button(buttons, SWT.PUSH); button.setText("Paste"); button.addListener(SWT.Selection, event -> { ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance()); if (imageData != null) { imageButton.setText(""); Image image = imageButton.getImage(); if (image != null) image.dispose(); image = new Image(display, imageData); imageButton.setImage(image); } else { imageButton.setText("No image"); imageButton.setImage(null); } String text = (String) clipboard.getContents(TextTransfer.getInstance()); if (text != null) { imageText.setText(text); } else { imageText.setText(""); } }); button = new Button(buttons, SWT.PUSH); button.setText("Clear"); button.addListener(SWT.Selection, event -> { imageButton.setText(""); Image image = imageButton.getImage(); if (image != null) image.dispose(); imageButton.setImage(null); imageText.setText(""); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet209.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true;//w w w . j a v a 2 s . c om final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data); canvas.setCurrent(); final GLContext context = GLDrawableFactory.getFactory().createExternalGLContext(); canvas.addListener(SWT.Resize, new Listener() { public void handleEvent(Event event) { Rectangle bounds = canvas.getBounds(); float fAspect = (float) bounds.width / (float) bounds.height; canvas.setCurrent(); context.makeCurrent(); GL gl = context.getGL(); gl.glViewport(0, 0, bounds.width, bounds.height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); GLU glu = new GLU(); glu.gluPerspective(45.0f, fAspect, 0.5f, 400.0f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); context.release(); } }); context.makeCurrent(); GL gl = context.getGL(); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); gl.glClearDepth(1.0); gl.glLineWidth(2); gl.glEnable(GL.GL_DEPTH_TEST); context.release(); shell.setText("SWT/JOGL Example"); shell.setSize(640, 480); shell.open(); display.asyncExec(new Runnable() { int rot = 0; public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); context.makeCurrent(); GL gl = context.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glClearColor(.3f, .5f, .8f, 1.0f); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -10.0f); float frot = rot; gl.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); gl.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); rot++; gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); gl.glColor3f(0.9f, 0.9f, 0.9f); drawTorus(gl, 1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); canvas.swapBuffers(); context.release(); display.asyncExec(this); } } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet209.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true;//from ww w. j av a 2s .co m final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data); canvas.setCurrent(); final GLContext context = GLDrawableFactory.getFactory(GLProfile.getGL2GL3()).createExternalGLContext(); ; canvas.addListener(SWT.Resize, new Listener() { @Override public void handleEvent(Event event) { Rectangle bounds = canvas.getBounds(); float fAspect = (float) bounds.width / (float) bounds.height; canvas.setCurrent(); context.makeCurrent(); GL2 gl = (GL2) context.getGL(); gl.glViewport(0, 0, bounds.width, bounds.height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); GLU glu = new GLU(); glu.gluPerspective(45.0f, fAspect, 0.5f, 400.0f); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); context.release(); } }); context.makeCurrent(); GL2 gl = (GL2) context.getGL(); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); gl.glClearDepth(1.0); gl.glLineWidth(2); gl.glEnable(GL.GL_DEPTH_TEST); context.release(); shell.setText("SWT/JOGL Example"); shell.setSize(640, 480); shell.open(); display.asyncExec(new Runnable() { int rot = 0; @Override public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); context.makeCurrent(); GL2 gl = (GL2) context.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glClearColor(.3f, .5f, .8f, 1.0f); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -10.0f); float frot = rot; gl.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); gl.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); rot++; gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2.GL_LINE); gl.glColor3f(0.9f, 0.9f, 0.9f); drawTorus(gl, 1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); canvas.swapBuffers(); context.release(); display.asyncExec(this); } } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet195.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true;//w w w . ja va 2 s .c o m final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data); canvas.setCurrent(); try { GLContext.useContext(canvas); } catch (LWJGLException e) { e.printStackTrace(); } canvas.addListener(SWT.Resize, new Listener() { public void handleEvent(Event event) { Rectangle bounds = canvas.getBounds(); float fAspect = (float) bounds.width / (float) bounds.height; canvas.setCurrent(); try { GLContext.useContext(canvas); } catch (LWJGLException e) { e.printStackTrace(); } GL11.glViewport(0, 0, bounds.width, bounds.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); } }); GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glClearDepth(1.0); GL11.glLineWidth(2); GL11.glEnable(GL11.GL_DEPTH_TEST); shell.setText("SWT/LWJGL Example"); shell.setSize(640, 480); shell.open(); display.asyncExec(new Runnable() { int rot = 0; public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); try { GLContext.useContext(canvas); } catch (LWJGLException e) { e.printStackTrace(); } GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClearColor(.3f, .5f, .8f, 1.0f); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -10.0f); float frot = rot; GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); rot++; GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); GL11.glColor3f(0.9f, 0.9f, 0.9f); drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); canvas.swapBuffers(); display.asyncExec(this); } } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:StackLayoutSwitchComposites.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 300, 200);/*from w ww . j a va 2s . co m*/ // create the composite that the pages will share final Composite contentPanel = new Composite(shell, SWT.BORDER); contentPanel.setBounds(100, 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(); // 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(10, 10, 80, 25); pageButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event 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:FormLayoutComposite.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FormLayout()); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 0;//from w w w.j av a 2 s . c o m 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); Button five = new Button(shell, SWT.PUSH); five.setText("five"); FormData data = new FormData(); data.top = new FormAttachment(two, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(two, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(100, -5); composite.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.examples.accessibility.AccessibleTableExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); shell.setText("Accessible Table Example"); Group group = new Group(shell, SWT.NONE); group.setText("Tables With Accessible Cell Children"); group.setLayout(new GridLayout()); new Label(group, SWT.NONE).setText("CTable with column headers"); table1 = new CTable(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); table1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table1.setHeaderVisible(true);//from w ww. ja v a2 s .c om table1.setLinesVisible(true); for (int col = 0; col < 3; col++) { CTableColumn column = new CTableColumn(table1, SWT.NONE); column.setText("Col " + col); column.setWidth(50); } for (int row = 0; row < 4; row++) { CTableItem item = new CTableItem(table1, SWT.NONE); item.setText(new String[] { "C0R" + row, "C1R" + row, "C2R" + row }); } Composite btnGroup = new Composite(group, SWT.NONE); btnGroup.setLayout(new FillLayout(SWT.VERTICAL)); Button btn = new Button(btnGroup, SWT.PUSH); btn.setText("Add rows"); btn.addSelectionListener(widgetSelectedAdapter(e -> { int currSize = table1.getItemCount(); int colCount = table1.getColumnCount(); CTableItem item = new CTableItem(table1, SWT.NONE); String[] cells = new String[colCount]; for (int i = 0; i < colCount; i++) { cells[i] = "C" + i + "R" + currSize; } item.setText(cells); })); btn = new Button(btnGroup, SWT.PUSH); btn.setText("Remove rows"); btn.addSelectionListener(widgetSelectedAdapter(e -> { int currSize = table1.getItemCount(); if (currSize > 0) { table1.remove(currSize - 1); } })); btn = new Button(btnGroup, SWT.PUSH); btn.setText("Remove selected rows"); btn.addSelectionListener(widgetSelectedAdapter(e -> { CTableItem[] selectedItems = table1.getSelection(); for (CTableItem selectedItem : selectedItems) { selectedItem.dispose(); } })); btn = new Button(btnGroup, SWT.PUSH); btn.setText("Add column"); btn.addSelectionListener(widgetSelectedAdapter(e -> { int currSize = table1.getColumnCount(); CTableColumn item = new CTableColumn(table1, SWT.NONE); item.setText("Col " + currSize); item.setWidth(50); })); btn = new Button(btnGroup, SWT.PUSH); btn.setText("Remove last column"); btn.addSelectionListener(widgetSelectedAdapter(e -> { int colCount = table1.getColumnCount(); if (colCount > 0) { CTableColumn column = table1.getColumn(colCount - 1); column.dispose(); } })); new Label(group, SWT.NONE).setText("CTable used as a list"); CTable table2 = new CTable(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); table2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table2.setLinesVisible(true); for (String element : itemText) { CTableItem item = new CTableItem(table2, SWT.NONE); item.setText(element); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }