List of usage examples for org.eclipse.swt.widgets Composite pack
public void pack()
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();/*w w w . ja v a2s.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:Snippet46.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); final Composite composite = new Composite(shell, SWT.NONE); composite.setEnabled(false);// www .j a va2 s . c o m composite.setLayout(new FillLayout()); Button button = new Button(composite, SWT.PUSH); button.setText("Button"); composite.pack(); composite.setLocation(10, 10); final Point[] offset = new Point[1]; Listener listener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.MouseDown: Rectangle rect = composite.getBounds(); if (rect.contains(event.x, event.y)) { Point pt1 = composite.toDisplay(0, 0); Point pt2 = shell.toDisplay(event.x, event.y); offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y); } break; case SWT.MouseMove: if (offset[0] != null) { Point pt = offset[0]; composite.setLocation(event.x - pt.x, event.y - pt.y); } break; case SWT.MouseUp: offset[0] = null; break; } } }; shell.addListener(SWT.MouseDown, listener); shell.addListener(SWT.MouseUp, listener); shell.addListener(SWT.MouseMove, listener); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet46.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 46"); final Composite composite = new Composite(shell, SWT.NONE); composite.setEnabled(false);//from w w w. ja v a 2 s. com composite.setLayout(new FillLayout()); Button button = new Button(composite, SWT.PUSH); button.setText("Button"); composite.pack(); composite.setLocation(10, 10); final Point[] offset = new Point[1]; Listener listener = event -> { switch (event.type) { case SWT.MouseDown: Rectangle rect = composite.getBounds(); if (rect.contains(event.x, event.y)) { Point pt1 = composite.toDisplay(0, 0); Point pt2 = shell.toDisplay(event.x, event.y); offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y); } break; case SWT.MouseMove: if (offset[0] != null) { Point pt = offset[0]; composite.setLocation(event.x - pt.x, event.y - pt.y); } break; case SWT.MouseUp: offset[0] = null; break; } }; shell.addListener(SWT.MouseDown, listener); shell.addListener(SWT.MouseUp, listener); shell.addListener(SWT.MouseMove, listener); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ControlListenerAdd.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout()); final Composite composite = new Composite(shell, SWT.BORDER); composite.setLayout(new RowLayout()); composite.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); composite.addControlListener(new ControlListener() { public void controlMoved(ControlEvent e) { }//from w w w . jav a2s . co m public void controlResized(ControlEvent e) { System.out.println("Composite resize."); } }); Button buttonAdd = new Button(shell, SWT.PUSH); buttonAdd.setText("Add new button"); buttonAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button button = new Button(composite, SWT.PUSH); button.setText("Button #" + (count++)); composite.layout(true); composite.pack(); } }); shell.setSize(450, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:HelloSWT_JFace.java
protected Control createContents(Composite parent) { Text helloText = new Text(parent, SWT.CENTER); helloText.setText("Hello SWT and JFace!"); parent.pack(); return parent; }
From source file:CoolBarExamples.java
public CoolBarExamples() { shell.setLayout(new GridLayout()); final CoolBar coolBar = new CoolBar(shell, SWT.NONE); coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // cool item with a text field. CoolItem textItem = new CoolItem(coolBar, SWT.NONE); Text text = new Text(coolBar, SWT.BORDER | SWT.DROP_DOWN); text.setText("TEXT"); text.pack();//from w ww .j a v a 2 s. co m Point size = text.getSize(); textItem.setControl(text); textItem.setSize(textItem.computeSize(size.x, size.y)); // cool item with a label. CoolItem labelItem = new CoolItem(coolBar, SWT.NONE); Label label = new Label(coolBar, SWT.NONE); label.setText("LABEL"); label.pack(); size = label.getSize(); labelItem.setControl(label); labelItem.setSize(textItem.computeSize(size.x, size.y)); // cool item with a button. CoolItem buttonItem = new CoolItem(coolBar, SWT.NONE | SWT.DROP_DOWN); Composite composite = new Composite(coolBar, SWT.NONE); composite.setLayout(new GridLayout(2, true)); Button button1 = new Button(composite, SWT.PUSH); button1.setText("Button 1"); button1.pack(); Button button2 = new Button(composite, SWT.PUSH); button2.setText("Button 2"); button2.pack(); composite.pack(); size = composite.getSize(); buttonItem.setControl(composite); buttonItem.setSize(buttonItem.computeSize(size.x, size.y)); // // Test cool item adding method. // Label label2 = new Label(coolBar, SWT.NONE); // label2.setText("label2"); // addControlToCoolBar(label2, SWT.DROP_DOWN, coolBar); try { setState(coolBar, new File("coolbar.state")); } catch (IOException e1) { e1.printStackTrace(); } shell.addListener(SWT.Close, new Listener() { public void handleEvent(Event event) { try { saveState(coolBar, new File("coolbar.state")); } catch (IOException e) { e.printStackTrace(); } } }); shell.setSize(300, 120); // shell.pack(); shell.open(); // 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:DumbUser.java
/** * Creates the main window's contents//from w w w . j av a 2s.co 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, true)); // Create the button Button show = new Button(composite, SWT.NONE); show.setText("Show"); final Shell shell = parent.getShell(); // Display the dialog show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create and show the dialog DumbMessageDialog dlg = new DumbMessageDialog(shell); dlg.open(); } }); parent.pack(); return composite; }
From source file:ShowMyTitleAreaDialog.java
/** * Creates the main window's contents// w w w. ja v a 2 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(1, true)); // Create the button Button show = new Button(composite, SWT.NONE); show.setText("Show"); final Shell shell = parent.getShell(); // Display the TitleAreaDialog show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create and show the dialog MyTitleAreaDialog dlg = new MyTitleAreaDialog(shell); dlg.open(); } }); parent.pack(); return composite; }
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);// w w w . j a va2s .co m else lv.removeFilter(filter); } }); parent.pack(); return composite; }
From source file:GetInput.java
/** * Creates the main window's contents//from w ww . java 2s . 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 label to display what the user typed in final Label label = new Label(composite, SWT.NONE); label.setText("This will display the user input from InputDialog"); // Create the button to launch the error dialog Button show = new Button(composite, SWT.PUSH); show.setText("Get Input"); show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter 5-8 characters", label.getText(), new LengthValidator()); if (dlg.open() == Window.OK) { // User clicked OK; update the label with the input label.setText(dlg.getValue()); } } }); parent.pack(); return composite; }