List of usage examples for org.eclipse.swt.widgets Composite Composite
public Composite(Composite parent, int style)
From source file:ShowError.java
/** * Creates the main window's contents/* w w w .j a va 2 s .c o m*/ * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); // Create a big text box to accept error text final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); text.setLayoutData(new GridData(GridData.FILL_BOTH)); // Create the button to launch the error dialog Button show = new Button(composite, SWT.PUSH); show.setText("Show Error"); show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the required Status object Status status = new Status(IStatus.ERROR, "My Plug-in ID", 0, "Status Error Message", null); // Display the dialog ErrorDialog.openError(Display.getCurrent().getActiveShell(), "JFace Error", text.getText(), status); } }); return composite; }
From source file:SashFormAdvanced.java
/** * Creates the main window's contents//from w ww .j av a2 s .c o m * * @param parent the parent window */ private void createContents(Composite parent) { // Our layout will have a row of buttons, and // then a SashForm below it. parent.setLayout(new GridLayout(1, false)); // Create the row of buttons Composite buttonBar = new Composite(parent, SWT.NONE); buttonBar.setLayout(new RowLayout()); Button flip = new Button(buttonBar, SWT.PUSH); flip.setText("Switch Orientation"); Button weights = new Button(buttonBar, SWT.PUSH); weights.setText("Restore Weights"); // Create the SashForm Composite sash = new Composite(parent, SWT.NONE); sash.setLayout(new FillLayout()); sash.setLayoutData(new GridData(GridData.FILL_BOTH)); final SashForm sashForm = new SashForm(sash, SWT.HORIZONTAL); // Change the width of the sashes sashForm.SASH_WIDTH = 20; // Change the color used to paint the sashes sashForm.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GREEN)); // Create the buttons and their event handlers final Button one = new Button(sashForm, SWT.PUSH); one.setText("One"); one.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(one, sashForm); } }); final Button two = new Button(sashForm, SWT.PUSH); two.setText("Two"); two.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(two, sashForm); } }); final Button three = new Button(sashForm, SWT.PUSH); three.setText("Three"); three.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(three, sashForm); } }); // Set the relative weights for the buttons sashForm.setWeights(new int[] { 1, 2, 3 }); // Add the Switch Orientation functionality flip.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { switch (sashForm.getOrientation()) { case SWT.HORIZONTAL: sashForm.setOrientation(SWT.VERTICAL); break; case SWT.VERTICAL: sashForm.setOrientation(SWT.HORIZONTAL); break; } } }); // Add the Restore Weights functionality weights.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { sashForm.setWeights(new int[] { 1, 2, 3 }); } }); }
From source file:EmailForm.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new FillLayout()); // Sets up the toolkit. FormToolkit toolkit = new FormToolkit(getShell().getDisplay()); // Creates a form instance. // Form form = toolkit.createForm(composite); ScrolledForm form = toolkit.createScrolledForm(composite); form.setLayoutData(new GridData(GridData.FILL_BOTH)); // Sets title. form.setText("Composing an Email Message"); // Adds body contents. form.getBody().setLayout(new GridLayout(2, false)); Label label = toolkit.createLabel(form.getBody(), "To: ", SWT.NULL); Text textTo = toolkit.createText(form.getBody(), ""); textTo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); label = toolkit.createLabel(form.getBody(), "Subject: ", SWT.NULL); Text textSubject = toolkit.createText(form.getBody(), ""); textSubject.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); label = toolkit.createLabel(form.getBody(), "Message: ", SWT.NULL); Text textMessage = toolkit.createText(form.getBody(), ""); textMessage.setLayoutData(new GridData(GridData.FILL_BOTH)); label = toolkit.createLabel(form.getBody(), "Option: ", SWT.NULL); Button buttonOption = toolkit.createButton(form.getBody(), "save a copy", SWT.CHECK); Button buttonClose = toolkit.createButton(form.getBody(), "Close", SWT.PUSH); GridData gridData = new GridData(); gridData.horizontalSpan = 2;/*from w w w.jav a 2 s . c o m*/ gridData.horizontalAlignment = GridData.END; buttonClose.setLayoutData(gridData); // Button button = toolkit.createButton(form.getBody(), "Test", SWT.NULL); // Adds tool bar items. form.getToolBarManager().add(new Action("Send") { public void run() { System.out.println("Sending email ..."); } }); form.getToolBarManager().add(new Action("Cancel") { public void run() { System.out.println("Cancelled."); } }); form.updateToolBar(); return composite; }
From source file:TemperatureConverterJFace.java
protected Control createContents(Composite parent) { getShell().setText("JFace Temperature Converter"); Composite converterComposite = new Composite(parent, SWT.NULL); converterComposite.setLayout(new GridLayout(4, false)); fahrenheitLabel = new Label(converterComposite, SWT.NULL); fahrenheitLabel.setText("Fahrenheit: "); fahrenheitValue = new Text(converterComposite, SWT.SINGLE | SWT.BORDER); celsiusLabel = new Label(converterComposite, SWT.NULL); celsiusLabel.setText("Celsius: "); celsiusValue = new Text(converterComposite, SWT.SINGLE | SWT.BORDER); ModifyListener listener = new ModifyListener() { public void modifyText(ModifyEvent e) { valueChanged((Text) e.widget); }/*from w w w. j ava2s .c o m*/ }; fahrenheitValue.addModifyListener(listener); celsiusValue.addModifyListener(listener); return converterComposite; }
From source file:RadioButtons.java
public RadioButtons() { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Label label = new Label(shell, SWT.NULL); label.setText("Gender: "); label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); Button femaleButton = new Button(shell, SWT.RADIO); femaleButton.setText("F"); Button maleButton = new Button(shell, SWT.RADIO); maleButton.setText("M"); label = new Label(shell, SWT.NULL); label.setText(" Title: "); label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); Composite composite = new Composite(shell, SWT.NULL); composite.setLayout(new RowLayout()); Button mrButton = new Button(composite, SWT.RADIO); mrButton.setText("Mr."); Button mrsButton = new Button(composite, SWT.RADIO); mrsButton.setText("Mrs."); Button msButton = new Button(composite, SWT.RADIO); msButton.setText("Ms."); Button drButton = new Button(composite, SWT.RADIO); drButton.setText("Dr."); shell.pack();/* w ww. j a v a 2 s. c om*/ shell.open(); //textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:RegistryTest.java
/** * Creates the window's contents//from w w w. j ava 2 s .co m * * @param parent the parent composite * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new FillLayout(SWT.VERTICAL)); // Set up the registries CR = new ColorRegistry(); CR.addListener(this); FR = new FontRegistry(); FR.addListener(this); // Create the label label = new Label(composite, SWT.CENTER); label.setText("Hello from JFace"); // Create the randomize button Button button = new Button(composite, SWT.PUSH); button.setText("Randomize"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { CR.put(FOREGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); CR.put(BACKGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); FontData fontData = new FontData("Times New Roman", (int) (Math.random() * 72), SWT.BOLD); FR.put(FONT, new FontData[] { fontData }); } }); return composite; }
From source file:ShowCTabFolder.java
/** * Creates the window's contents//from ww w.java 2 s. c om * * @param shell the parent shell */ private void createContents(Shell shell) { shell.setLayout(new GridLayout(1, true)); // Create the buttons to create tabs Composite composite = new Composite(shell, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); composite.setLayout(new RowLayout()); createButtons(composite); // Create the tabs tabFolder = new CTabFolder(shell, SWT.TOP); tabFolder.setBorderVisible(true); tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); Display display = shell.getDisplay(); // Set up a gradient background for the selected tab tabFolder.setSelectionBackground(new Color[] { display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW), display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW) }, new int[] { 50, 100 }); // Add a listener to get the close button on each tab tabFolder.addCTabFolderListener(new CTabFolderAdapter() { public void itemClosed(CTabFolderEvent event) { } }); }
From source file:MainClass.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button filterButton = new Button(composite, SWT.CHECK); filterButton.setText("&Show only healthy"); final ListViewer lv = new ListViewer(composite); lv.setContentProvider(new ItemContentProvider()); lv.setLabelProvider(new ItemLabelProvider()); lv.setInput(new ItemList()); filterButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (((Button) event.widget).getSelection()) lv.addFilter(filter);/*from w ww .j a v a2 s . c om*/ else lv.removeFilter(filter); } }); parent.pack(); return composite; }
From source file:SendMessage.java
/** * Creates the main window's contents//from w w w. j a v a2 s . c om * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(5, true)); // Create a big text box for the message text final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 5; text.setLayoutData(data); // Create the Confirm button Button confirm = new Button(composite, SWT.PUSH); confirm.setText("Confirm"); confirm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Error button Button error = new Button(composite, SWT.PUSH); error.setText("Error"); error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Information button Button information = new Button(composite, SWT.PUSH); information.setText("Information"); information.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Question button Button question = new Button(composite, SWT.PUSH); question.setText("Question"); question.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Warning button Button warning = new Button(composite, SWT.PUSH); warning.setText("Warning"); warning.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the label to display the return value final Label label = new Label(composite, SWT.NONE); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 5; label.setLayoutData(data); // Save ourselves some typing final Shell shell = parent.getShell(); // Display a Confirmation dialog confirm.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean b = MessageDialog.openConfirm(shell, "Confirm", text.getText()); label.setText("Returned " + Boolean.toString(b)); } }); // Display an Error dialog error.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openError(shell, "Error", text.getText()); label.setText("Returned void"); } }); // Display an Information dialog information.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openInformation(shell, "Information", text.getText()); label.setText("Returned void"); } }); // Display a Question dialog question.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean b = MessageDialog.openQuestion(shell, "Question", text.getText()); label.setText("Returned " + Boolean.toString(b)); } }); // Display a Warning dialog warning.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openWarning(shell, "Warning", text.getText()); label.setText("Returned void"); } }); return composite; }
From source file:SharedMenu.java
private void menu() { shell.setLayout(new GridLayout(2, true)); final Composite composite1 = new Composite(shell, SWT.BORDER); composite1.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); final Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); Menu menu = new Menu(composite1); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Popup menu"); menuItem.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { System.out.println("Menu item is disposed."); }//from w w w .j a v a 2s . c om }); menuItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { System.out.println("Dispsoing ..."); //composite2.setMenu(null); composite2.dispose(); } }); composite1.setMenu(menu); composite2.setMenu(menu); }