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:Snippet40.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Composite c1 = new Composite(shell, SWT.BORDER); c1.setSize(100, 100);/*from w w w .j a v a 2s . c om*/ Composite c2 = new Composite(shell, SWT.BORDER); c2.setBounds(100, 0, 100, 100); Menu menu = new Menu(shell, SWT.POP_UP); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText("Popup"); c1.setMenu(menu); c2.setMenu(menu); shell.setMenu(menu); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:PopupMenuAddTwoControls.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Composite c1 = new Composite(shell, SWT.BORDER); c1.setSize(100, 100);/*from ww w .j av a2 s. c o m*/ Composite c2 = new Composite(shell, SWT.BORDER); c2.setBounds(100, 0, 100, 100); Menu menu = new Menu(shell, SWT.POP_UP); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText("Popup"); c1.setMenu(menu); c2.setMenu(menu); shell.setMenu(menu); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:EmbedSwingAWTSWT.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("SWT and Swing/AWT Example"); Composite treeComp = new Composite(shell, SWT.EMBEDDED); treeComp.setBounds(5, 5, 300, 300); java.awt.Frame fileTableFrame = SWT_AWT.new_Frame(treeComp); java.awt.Panel panel = new java.awt.Panel(new java.awt.BorderLayout()); fileTableFrame.add(panel);/*from ww w . j a v a2 s . c o m*/ JTree fileTable = new JTree(); fileTable.setDoubleBuffered(true); JScrollPane scrollPane = new JScrollPane(fileTable); panel.add(scrollPane); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet249.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 249"); Rectangle clientArea = shell.getClientArea(); shell.setBounds(clientArea.x + 10, clientArea.y + 10, 300, 200); // create the composite that the pages will share final Composite contentPanel = new Composite(shell, SWT.BORDER); contentPanel.setBounds(clientArea.x + 100, clientArea.y + 10, 190, 90); final StackLayout layout = new StackLayout(); contentPanel.setLayout(layout);/*from ww w.jav a 2s . c o m*/ // 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(clientArea.x + 10, clientArea.y + 10, 80, 25); pageButton.addListener(SWT.Selection, 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:StackLayoutSwitchComposites.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 300, 200);/*w w w . j a v a2s .c om*/ // 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:org.eclipse.swt.snippets.Snippet238.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 238"); Composite composite = new Composite(shell, SWT.BORDER); Rectangle clientArea = shell.getClientArea(); composite.setBounds(clientArea.x, clientArea.y, 100, 100); Menu menu = new Menu(shell, SWT.POP_UP); MenuItem item1 = new MenuItem(menu, SWT.PUSH); item1.setText("Push Item"); MenuItem item2 = new MenuItem(menu, SWT.CASCADE); item2.setText("Cascade Item"); Menu subMenu = new Menu(menu); item2.setMenu(subMenu);/*from w ww .ja va 2 s . c om*/ MenuItem subItem1 = new MenuItem(subMenu, SWT.PUSH); subItem1.setText("Subitem 1"); MenuItem subItem2 = new MenuItem(subMenu, SWT.PUSH); subItem2.setText("Subitem 2"); composite.setMenu(menu); shell.setMenu(menu); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ControlEditorWithDialog.java
public static void main(String[] args) { final Shell shell = new Shell(display); shell.setText("Control Editor Two"); final Composite composite = new Composite(shell, SWT.NONE); composite.setBackground(color);// w w w.j a v a 2 s. c om composite.setBounds(0, 0, 300, 100); ControlEditor editor = new ControlEditor(composite); // Create the control associated with the editor Button button = new Button(composite, SWT.PUSH); button.setText("Change Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ColorDialog dialog = new ColorDialog(shell); if (color != null) dialog.setRGB(color.getRGB()); RGB rgb = dialog.open(); if (rgb != null) { if (color != null) color.dispose(); color = new Color(shell.getDisplay(), rgb); composite.setBackground(color); } } }); // Place the editor along the bottom of the parent composite editor.grabHorizontal = true; editor.verticalAlignment = SWT.BOTTOM; Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); editor.minimumHeight = size.y; editor.setEditor(button); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } if (color != null) color.dispose(); display.dispose(); }
From source file:ControlEditorSample.java
public static void main(String[] args) { final Shell shell = new Shell(display); shell.setText("Control Editor"); final Composite composite = new Composite(shell, SWT.NONE); composite.setBackground(color);/*from w w w . j a va 2 s . c om*/ composite.setBounds(0, 0, 300, 100); ControlEditor editor = new ControlEditor(composite); 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); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } if (color != null) color.dispose(); display.dispose(); }
From source file:WidgetTest2.java
public static Composite createComposite(Composite parent) { /** * Composite ** */ // Create new Composite instance final Composite composite = new Composite(parent, 0); // Get properties from the containing composite composite.setBackground(parent.getBackground()); composite.setForeground(parent.getForeground()); composite.setFont(parent.getFont()); // Set position and size composite.setBounds(X, Y, WIDTH, HEIGHT); return composite; }
From source file:ControlEditorTestTwo.java
/** * Creates the main window's contents//from w ww . ja v a2 s . c om * * @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 Button button = new Button(composite, SWT.PUSH); button.setText("Change Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ColorDialog dialog = new ColorDialog(shell); if (color != null) dialog.setRGB(color.getRGB()); RGB rgb = dialog.open(); if (rgb != null) { if (color != null) color.dispose(); color = new Color(shell.getDisplay(), rgb); composite.setBackground(color); } } }); // Place the editor along the bottom of the parent composite editor.grabHorizontal = true; editor.verticalAlignment = SWT.BOTTOM; Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); editor.minimumHeight = size.y; editor.setEditor(button); }