List of usage examples for org.eclipse.swt.widgets Composite layout
Layout layout
To view the source code for org.eclipse.swt.widgets Composite layout.
Click Source Link
From source file:Look.java
/** * Creates the main window's contents/*from w w w . ja v a 2s . c o m*/ * * @param parent the main window */ public void createContents(Composite parent) { parent.setLayout(new GridLayout(1, false)); // Pressing the "New Document" button will create a new ViewForm Button button = new Button(parent, SWT.PUSH); button.setText("New Document"); // Create the composite that holds the ViewForms final Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new FillLayout()); // Add the event handler to create the ViewForms button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { createViewFormHelper(composite, "Document " + (++count)); composite.layout(); } }); }
From source file:org.amanzi.splash.editors.SplashJFreeChartEditor.java
/** * @see org.eclipse.ui.IWorkbenchPart#createPartControl(Composite) *///from w w w . ja v a 2 s . c o m public void createPartControl(final Composite parent) { ChartNode chartNode = getChartNode(); JFreeChart chart = Charts.createBarChart(Charts.createBarChartDataset(chartNode)); new ChartComposite(parent, SWT.NONE, chart, true, true, true, true, true); parent.layout(); }
From source file:SWTBrowserDemo.java
public SWTBrowserDemo(Composite parent, boolean top) { this.parent = parent; try {//from w ww .j a v a2s . com browser = new Browser(parent, SWT.BORDER); } catch (SWTError e) { error = e; /* Browser widget could not be instantiated */ parent.setLayout(new FillLayout()); Label label = new Label(parent, SWT.CENTER | SWT.WRAP); label.setText(getResourceString("BrowserNotCreated")); parent.layout(true); return; } initResources(); final Display display = parent.getDisplay(); browser.setData("org.eclipse.swt.examples.browserexample.BrowserApplication", this); browser.addOpenWindowListener(new OpenWindowListener() { public void open(WindowEvent event) { Shell shell = new Shell(display); if (icon != null) shell.setImage(icon); shell.setLayout(new FillLayout()); SWTBrowserDemo app = new SWTBrowserDemo(shell, false); app.setShellDecoration(icon, true); event.browser = app.getBrowser(); } }); if (top) { browser.setUrl(getResourceString("Startup")); show(false, null, null, true, true, true, true); } else { browser.addVisibilityWindowListener(new VisibilityWindowListener() { public void hide(WindowEvent e) { } public void show(WindowEvent e) { Browser browser = (Browser) e.widget; SWTBrowserDemo app = (SWTBrowserDemo) browser .getData("org.eclipse.swt.examples.browserexample.BrowserApplication"); app.show(true, e.location, e.size, e.addressBar, e.menuBar, e.statusBar, e.toolBar); } }); browser.addCloseWindowListener(new CloseWindowListener() { public void close(WindowEvent event) { Browser browser = (Browser) event.widget; Shell shell = browser.getShell(); shell.close(); } }); } }
From source file:Look.java
/** * Helper function for creating the ViewForms * //from w w w . ja va 2 s . c om * @param parent the parent Composite * @param text the title text */ private void createViewFormHelper(final Composite parent, String text) { // Create the ViewForm final ViewForm vf = new ViewForm(parent, SWT.BORDER); // Create the CLabel for the top left, which will have an image and text CLabel label = new CLabel(vf, SWT.NONE); label.setText(text); label.setImage(lookImage); label.setAlignment(SWT.LEFT); vf.setTopLeft(label); // Create the downward-pointing arrow to display the menu // and set it as the top center final ToolBar tbMenu = new ToolBar(vf, SWT.FLAT); final ToolItem itemMenu = new ToolItem(tbMenu, SWT.PUSH); itemMenu.setImage(menuImage); vf.setTopCenter(tbMenu); // Create the close button and set it as the top right ToolBar tbClose = new ToolBar(vf, SWT.FLAT); ToolItem itemClose = new ToolItem(tbClose, SWT.PUSH); itemClose.setText("X"); itemClose.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { vf.dispose(); parent.layout(); } }); vf.setTopRight(tbClose); // Create the content--a multi-line text box final Text textArea = new Text(vf, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); vf.setContent(textArea); /* Create the menu to display when the down arrow is pressed */ final Menu menu = new Menu(tbMenu); MenuItem clear = new MenuItem(menu, SWT.NONE); clear.setText("Clear"); clear.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { textArea.setText(""); } }); // Add the handler to display the menu itemMenu.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Place the menu right below the toolbar button Rectangle rect = itemMenu.getBounds(); menu.setLocation(tbMenu.toDisplay(rect.x, rect.y + rect.height)); menu.setVisible(true); } }); }
From source file:org.eclipse.swt.examples.browser.demos.views.EditorTab.java
public EditorTab(TabItem item) { final Composite parent = new Composite(item.getParent(), SWT.NONE); item.setText("Editor"); item.setControl(parent);/*from w ww. j a v a 2 s . c om*/ try { browser = new Browser(parent, SWT.NONE); } catch (SWTError e) { e.printStackTrace(); return; } final Sash sash = new Sash(parent, SWT.VERTICAL); Composite panel = new Composite(parent, SWT.NONE); final FormLayout form = new FormLayout(); parent.setLayout(form); FormData data = new FormData(); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(sash, 0); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(100, 0); browser.setLayoutData(data); final FormData sashData = new FormData(); sashData.left = new FormAttachment(50, 0); sashData.top = new FormAttachment(0, 0); sashData.bottom = new FormAttachment(100, 0); sash.setLayoutData(sashData); sash.addListener(SWT.Selection, e -> { Rectangle rect = sash.getBounds(); Rectangle parentRect = sash.getParent().getClientArea(); int right = parentRect.width - rect.width - 20; e.x = Math.max(Math.min(e.x, right), 20); if (e.x != rect.x) { sashData.left = new FormAttachment(0, e.x); parent.layout(); } }); data = new FormData(); data.left = new FormAttachment(sash, 0); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(100, 0); panel.setLayoutData(data); /* Initialize Panel */ panel.setLayout(new FillLayout(SWT.VERTICAL)); Group htmlGroup = new Group(panel, SWT.NONE); htmlGroup.setText("setText"); htmlText = new Text(htmlGroup, SWT.MULTI); htmlButton = new Button(htmlGroup, SWT.PUSH); htmlButton.setText("setText"); GridLayout gridLayout = new GridLayout(); htmlGroup.setLayout(gridLayout); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; htmlText.setLayoutData(gridData); gridData = new GridData(); gridData.horizontalAlignment = GridData.END; htmlButton.setLayoutData(gridData); htmlGroup.layout(); Group scriptGroup = new Group(panel, SWT.NONE); scriptGroup.setText("execute"); scriptText = new Text(scriptGroup, SWT.MULTI); scriptButton = new Button(scriptGroup, SWT.PUSH); scriptButton.setText("execute"); gridLayout = new GridLayout(); scriptGroup.setLayout(gridLayout); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; scriptText.setLayoutData(gridData); gridData = new GridData(); gridData.horizontalAlignment = GridData.END; scriptButton.setLayoutData(gridData); scriptGroup.layout(); browser.setText(html); htmlText.setText(html); scriptText.setText(script); parent.layout(); Listener listener = e -> { Widget w = e.widget; if (w == htmlButton) browser.setText(htmlText.getText()); if (w == scriptButton) browser.execute(scriptText.getText()); }; htmlButton.addListener(SWT.Selection, listener); scriptButton.addListener(SWT.Selection, listener); }
From source file:org.eclipse.swt.examples.dnd.DNDExample.java
private void createDragWidget(Composite parent) { parent.setLayout(new FormLayout()); Combo combo = new Combo(parent, SWT.READ_ONLY); combo.setItems("Toggle Button", "Radio Button", "Checkbox", "Canvas", "Label", "List", "Table", "Tree", "Text", "StyledText", "Combo"); combo.select(LABEL);//w w w . j ava 2s.c o m dragControlType = combo.getSelectionIndex(); dragControl = createWidget(dragControlType, parent, "Drag Source"); combo.addSelectionListener(widgetSelectedAdapter(e -> { Object data = dragControl.getLayoutData(); Composite dragParent = dragControl.getParent(); dragControl.dispose(); Combo c = (Combo) e.widget; dragControlType = c.getSelectionIndex(); dragControl = createWidget(dragControlType, dragParent, "Drag Source"); dragControl.setLayoutData(data); if (dragEnabled) createDragSource(); dragParent.layout(); })); Button b = new Button(parent, SWT.CHECK); b.setText("DragSource"); b.addSelectionListener(widgetSelectedAdapter(e -> { Button b1 = (Button) e.widget; dragEnabled = b1.getSelection(); if (dragEnabled) { createDragSource(); } else { if (dragSource != null) { dragSource.dispose(); } dragSource = null; } })); b.setSelection(true); dragEnabled = true; FormData data = new FormData(); data.top = new FormAttachment(0, 10); data.bottom = new FormAttachment(combo, -10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(100, -10); dragControl.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(0, 10); combo.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(combo, 10); b.setLayoutData(data); }
From source file:org.eclipse.swt.examples.dnd.DNDExample.java
private void createDropWidget(Composite parent) { parent.setLayout(new FormLayout()); Combo combo = new Combo(parent, SWT.READ_ONLY); combo.setItems("Toggle Button", "Radio Button", "Checkbox", "Canvas", "Label", "List", "Table", "Tree", "Text", "StyledText", "Combo"); combo.select(LABEL);/*from w w w.ja v a2 s .c o m*/ dropControlType = combo.getSelectionIndex(); dropControl = createWidget(dropControlType, parent, "Drop Target"); combo.addSelectionListener(widgetSelectedAdapter(e -> { Object data = dropControl.getLayoutData(); Composite dropParent = dropControl.getParent(); dropControl.dispose(); Combo c = (Combo) e.widget; dropControlType = c.getSelectionIndex(); dropControl = createWidget(dropControlType, dropParent, "Drop Target"); dropControl.setLayoutData(data); if (dropEnabled) createDropTarget(); dropParent.layout(); })); Button b = new Button(parent, SWT.CHECK); b.setText("DropTarget"); b.addSelectionListener(widgetSelectedAdapter(e -> { Button eb = (Button) e.widget; dropEnabled = eb.getSelection(); if (dropEnabled) { createDropTarget(); } else { if (dropTarget != null) { dropTarget.dispose(); } dropTarget = null; } })); // initialize state b.setSelection(true); dropEnabled = true; FormData data = new FormData(); data.top = new FormAttachment(0, 10); data.bottom = new FormAttachment(combo, -10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(100, -10); dropControl.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(0, 10); combo.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(combo, 10); b.setLayoutData(data); }
From source file:GraphicsExample.java
public GraphicsExample(final Composite parent) { this.parent = parent; redrawListener = new Listener() { public void handleEvent(Event e) { redraw();/*from w ww .j a va 2 s . co m*/ } }; GridData data; GridLayout layout = new GridLayout(3, false); layout.horizontalSpacing = 1; parent.setLayout(layout); tabs = createTabs(); images = new Vector(); createToolBar(parent); createTabList(parent); final Sash sash = new Sash(parent, SWT.VERTICAL); createTabPanel(parent); data = new GridData(SWT.FILL, SWT.CENTER, true, false); data.horizontalSpan = 3; toolBar.setLayoutData(data); data = new GridData(SWT.CENTER, SWT.FILL, false, true); data.widthHint = tabList.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + 50; tabList.setLayoutData(data); data = new GridData(SWT.CENTER, SWT.FILL, false, true); sash.setLayoutData(data); data = new GridData(SWT.FILL, SWT.FILL, true, true); tabPanel.setLayoutData(data); sash.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (event.detail != SWT.DRAG) { GridData data = (GridData) tabList.getLayoutData(); data.widthHint = event.x - tabList.computeTrim(0, 0, 0, 0).width; parent.layout(true); animate = pauseItem.getEnabled(); } else { animate = false; } } }); setTab(tab); startAnimationTimer(); }
From source file:DNDExample.java
private void createDragWidget(Composite parent) { parent.setLayout(new FormLayout()); Combo combo = new Combo(parent, SWT.READ_ONLY); combo.setItems(new String[] { "Toggle Button", "Radio Button", "Checkbox", "Canvas", "Label", "List", "Table", "Tree" }); combo.select(LABEL);//from w w w. ja va 2 s.com dragControlType = combo.getSelectionIndex(); dragControl = createWidget(dragControlType, parent, "Drag Source"); combo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Object data = dragControl.getLayoutData(); Composite parent = dragControl.getParent(); dragControl.dispose(); Combo c = (Combo) e.widget; dragControlType = c.getSelectionIndex(); dragControl = createWidget(dragControlType, parent, "Drag Source"); dragControl.setLayoutData(data); if (dragEnabled) createDragSource(); parent.layout(); } }); Button b = new Button(parent, SWT.CHECK); b.setText("DragSource"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; dragEnabled = b.getSelection(); if (dragEnabled) { createDragSource(); } else { if (dragSource != null) { dragSource.dispose(); } dragSource = null; } } }); FormData data = new FormData(); data.top = new FormAttachment(0, 10); data.bottom = new FormAttachment(combo, -10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(100, -10); dragControl.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(0, 10); combo.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(combo, 10); b.setLayoutData(data); }
From source file:DNDExample.java
private void createDropWidget(Composite parent) { parent.setLayout(new FormLayout()); Combo combo = new Combo(parent, SWT.READ_ONLY); combo.setItems(new String[] { "Toggle Button", "Radio Button", "Checkbox", "Canvas", "Label", "List", "Table", "Tree", "Text" }); combo.select(LABEL);/* www .ja va 2s.com*/ dropControlType = combo.getSelectionIndex(); dropControl = createWidget(dropControlType, parent, "Drop Target"); combo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Object data = dropControl.getLayoutData(); Composite parent = dropControl.getParent(); dropControl.dispose(); Combo c = (Combo) e.widget; dropControlType = c.getSelectionIndex(); dropControl = createWidget(dropControlType, parent, "Drop Target"); dropControl.setLayoutData(data); if (dropEnabled) createDropTarget(); parent.layout(); } }); Button b = new Button(parent, SWT.CHECK); b.setText("DropTarget"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; dropEnabled = b.getSelection(); if (dropEnabled) { createDropTarget(); } else { if (dropTarget != null) { dropTarget.dispose(); } dropTarget = null; } } }); FormData data = new FormData(); data.top = new FormAttachment(0, 10); data.bottom = new FormAttachment(combo, -10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(100, -10); dropControl.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(0, 10); combo.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(combo, 10); b.setLayoutData(data); }