List of usage examples for org.eclipse.swt.widgets Composite setBounds
public void setBounds(int x, int y, int width, int height)
From source file:ControlEditorTest.java
/** * Creates the main window's contents/* w w w . ja v a2 s . co m*/ * * @param shell the main window */ private void createContents(final Shell shell) { color = new Color(shell.getDisplay(), 255, 0, 0); // Create a composite that will be the parent of the editor final Composite composite = new Composite(shell, SWT.NONE); composite.setBackground(color); composite.setBounds(0, 0, 300, 100); // Create the editor ControlEditor editor = new ControlEditor(composite); // Create the control associated with the editor final Text text = new Text(composite, SWT.BORDER); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { RGB rgb = (RGB) COLORS.get(text.getText()); if (rgb != null) { if (color != null) color.dispose(); color = new Color(shell.getDisplay(), rgb); composite.setBackground(color); } } }); // Place the editor in the top middle of the parent composite editor.horizontalAlignment = SWT.CENTER; editor.verticalAlignment = SWT.TOP; Point size = text.computeSize(SWT.DEFAULT, SWT.DEFAULT); editor.minimumWidth = size.x; editor.minimumHeight = size.y; editor.setEditor(text); }
From source file:org.eclipse.swt.snippets.Snippet319.java
public void go() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 319"); shell.setBounds(10, 10, 600, 200);//from w w w. ja v a2 s .co m /* Create SWT controls and add drag source */ final Label swtLabel = new Label(shell, SWT.BORDER); swtLabel.setBounds(10, 10, 580, 50); swtLabel.setText("SWT drag source"); DragSource dragSource = new DragSource(swtLabel, DND.DROP_COPY); dragSource.setTransfer(new MyTypeTransfer()); dragSource.addDragListener(new DragSourceAdapter() { @Override public void dragSetData(DragSourceEvent event) { MyType object = new MyType(); object.name = "content dragged from SWT"; object.time = System.currentTimeMillis(); event.data = object; } }); /* Create AWT/Swing controls */ Composite embeddedComposite = new Composite(shell, SWT.EMBEDDED); embeddedComposite.setBounds(10, 100, 580, 50); embeddedComposite.setLayout(new FillLayout()); Frame frame = SWT_AWT.new_Frame(embeddedComposite); final JLabel jLabel = new JLabel("AWT/Swing drop target"); frame.add(jLabel); /* Register the custom data flavour */ final DataFlavor flavor = new DataFlavor(MIME_TYPE, "MyType custom flavor"); /* * Note that according to jre/lib/flavormap.properties, the preferred way to * augment the default system flavor map is to specify the AWT.DnD.flavorMapFileURL * property in an awt.properties file. * * This snippet uses the alternate approach below in order to provide a simple * stand-alone snippet that demonstrates the functionality. This implementation * works well, but if the instanceof check below fails for some reason when used * in a different context then the drop will not be accepted. */ FlavorMap map = SystemFlavorMap.getDefaultFlavorMap(); if (map instanceof SystemFlavorMap) { SystemFlavorMap systemMap = (SystemFlavorMap) map; systemMap.addFlavorForUnencodedNative(MIME_TYPE, flavor); } /* add drop target */ DropTargetListener dropTargetListener = new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dropTargetDropEvent) { try { dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY); ByteArrayInputStream inStream = (ByteArrayInputStream) dropTargetDropEvent.getTransferable() .getTransferData(flavor); int available = inStream.available(); byte[] bytes = new byte[available]; inStream.read(bytes); MyType object = restoreFromByteArray(bytes); String string = object.name + ": " + new Date(object.time).toString(); jLabel.setText(string); } catch (Exception e) { e.printStackTrace(); } } }; new DropTarget(jLabel, dropTargetListener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }