List of usage examples for org.eclipse.swt.widgets Composite Composite
public Composite(Composite parent, int style)
From source file:org.eclipse.swt.snippets.Snippet188.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 188"); shell.setLayout(new GridLayout()); final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); Composite c = new Composite(sc, SWT.NONE); c.setLayout(new GridLayout(10, true)); for (int i = 0; i < 300; i++) { Button b = new Button(c, SWT.PUSH); b.setText("Button " + i); }//from www . j av a2 s . c o m sc.setContent(c); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT)); sc.setShowFocusedControl(true); shell.setSize(300, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet154.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 154"); shell.setLayout(new FillLayout()); Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED); /*//from www. j ava2s. c o m * Set a Windows specific AWT property that prevents heavyweight * components from erasing their background. Note that this * is a global property and cannot be scoped. It might not be * suitable for your application. */ try { System.setProperty("sun.awt.noerasebackground", "true"); } catch (NoSuchMethodError error) { } /* Create and setting up frame */ Frame frame = SWT_AWT.new_Frame(composite); Panel panel = new Panel(new BorderLayout()) { @Override public void update(java.awt.Graphics g) { /* Do not erase the background */ paint(g); } }; frame.add(panel); JRootPane root = new JRootPane(); panel.add(root); java.awt.Container contentPane = root.getContentPane(); /* Creating components */ int nrows = 1000, ncolumns = 10; Vector<Vector<String>> rows = new Vector<>(); for (int i = 0; i < nrows; i++) { Vector<String> row = new Vector<>(); for (int j = 0; j < ncolumns; j++) { row.addElement("Item " + i + "-" + j); } rows.addElement(row); } Vector<String> columns = new Vector<>(); for (int i = 0; i < ncolumns; i++) { columns.addElement("Column " + i); } JTable table = new JTable(rows, columns); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.createDefaultColumnsFromModel(); JScrollPane scrollPane = new JScrollPane(table); contentPane.setLayout(new BorderLayout()); contentPane.add(scrollPane); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
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 .jav a 2s . co m*/ 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:org.eclipse.swt.snippets.Snippet343.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 343"); shell.setLayout(new FillLayout()); shell.setSize(400, 400);/*w w w . j a v a 2s. c o m*/ SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL); Composite leftComposite = new Composite(sashForm, SWT.NONE); leftComposite.setLayout(new FillLayout()); Composite rightComposite = new Composite(sashForm, SWT.NONE); rightComposite.setLayout(new FillLayout()); ExpandBar expandBar = new ExpandBar(leftComposite, SWT.NONE); final ExpandItem expandItem1 = new ExpandItem(expandBar, SWT.NONE); expandItem1.setText("item 1"); new ExpandItem(expandBar, SWT.NONE).setText("item 2"); /* expandItem2 */ final StyledText text = new StyledText(expandBar, SWT.MULTI | SWT.WRAP); expandItem1.setControl(text); text.setText("initial text that will wrap if it's long enough"); /* update the item's height if needed in response to changes in the text's size */ final int TRIAL_WIDTH = 100; final int trimWidth = text.computeTrim(0, 0, TRIAL_WIDTH, 100).width - TRIAL_WIDTH; text.addListener(SWT.Modify, event -> { Point size = text.computeSize(text.getSize().x - trimWidth, SWT.DEFAULT); if (expandItem1.getHeight() != size.y) { expandItem1.setHeight(size.y); } }); expandBar.addListener(SWT.Resize, event -> display.asyncExec(() -> { /* * The following is done asynchronously to allow the Text's width * to be changed before re-calculating its preferred height. */ if (text.isDisposed()) return; Point size = text.computeSize(text.getSize().x - trimWidth, SWT.DEFAULT); if (expandItem1.getHeight() != size.y) { expandItem1.setHeight(size.y); } })); shell.open(); /* set the item's initial height */ Point size = text.computeSize(expandBar.getClientArea().width, SWT.DEFAULT); expandItem1.setHeight(size.y); expandItem1.setExpanded(true); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:SashFormThreeChildren.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); SashForm form = new SashForm(shell, SWT.HORIZONTAL); form.setLayout(new FillLayout()); Composite child1 = new Composite(form, SWT.NONE); child1.setLayout(new FillLayout()); new Label(child1, SWT.NONE).setText("Label in pane 1"); Composite child2 = new Composite(form, SWT.NONE); child2.setLayout(new FillLayout()); new Button(child2, SWT.PUSH).setText("Button in pane2"); Composite child3 = new Composite(form, SWT.NONE); child3.setLayout(new FillLayout()); new Label(child3, SWT.PUSH).setText("Label in pane3"); form.setWeights(new int[] { 30, 40, 30 }); shell.open();// w w w . j ava 2 s .c o m while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet266.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 266"); shell.setLayout(new GridLayout(2, true)); TabFolder tabFolder = new TabFolder(shell, SWT.NONE); tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText("Widget"); Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new GridLayout()); Tree tree = new Tree(composite, SWT.BORDER); item.setControl(composite);/*from ww w . ja v a 2s . co m*/ tree.setHeaderVisible(true); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); TreeColumn column1 = new TreeColumn(tree, SWT.NONE); column1.setText("Standard"); TreeColumn column2 = new TreeColumn(tree, SWT.NONE); column2.setText("Widget"); TreeItem branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Efficient", "Portable" }); TreeItem leaf = new TreeItem(branch, SWT.NONE); leaf.setText(new String[] { "Cross", "Platform" }); branch.setExpanded(true); branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Native", "Controls" }); leaf = new TreeItem(branch, SWT.NONE); leaf.setText(new String[] { "Cross", "Platform" }); branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Cross", "Platform" }); column1.pack(); column2.pack(); item = new TabItem(tabFolder, SWT.NONE); item.setText("Toolkit"); Button button = new Button(shell, SWT.CHECK); button.setText("Totally"); button.setSelection(true); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); button = new Button(shell, SWT.PUSH); button.setText("Awesome"); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); shell.pack(); 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 w w w . j a v a 2s.c om*/ // 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:org.eclipse.swt.snippets.Snippet223.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = display.getSystemImage(SWT.ICON_QUESTION); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;//from w w w .j a v a 2s .com composite.setLayout(layout); Button button = new Button(composite, SWT.PUSH); button.setText("SWT.PUSH"); button = new Button(composite, SWT.RADIO); button.setText("SWT.RADIO"); button = new Button(composite, SWT.CHECK); button.setText("SWT.CHECK"); button = new Button(composite, SWT.TOGGLE); button.setText("SWT.TOGGLE"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); // Second item composite = new Composite(bar, SWT.NONE); layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10; composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_QUESTION"); ExpandItem item1 = new ExpandItem(bar, SWT.NONE, 1); item1.setText("What is your favorite icon"); item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item1.setControl(composite); item1.setImage(image); // Third item composite = new Composite(bar, SWT.NONE); layout = new GridLayout(2, true); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10; composite.setLayout(layout); label = new Label(composite, SWT.NONE); label.setText("Scale"); new Scale(composite, SWT.NONE); label = new Label(composite, SWT.NONE); label.setText("Spinner"); new Spinner(composite, SWT.BORDER); label = new Label(composite, SWT.NONE); label.setText("Slider"); new Slider(composite, SWT.NONE); ExpandItem item2 = new ExpandItem(bar, SWT.NONE, 2); item2.setText("What is your favorite range widget"); item2.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item2.setControl(composite); item2.setImage(image); item1.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:EmbedJTableSWTNoFlicker.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED); /*/*w w w .j a v a 2 s . c o m*/ * Set a Windows specific AWT property that prevents heavyweight components * from erasing their background. Note that this is a global property and * cannot be scoped. It might not be suitable for your application. */ try { System.setProperty("sun.awt.noerasebackground", "true"); } catch (NoSuchMethodError error) { } /* Create and setting up frame */ Frame frame = SWT_AWT.new_Frame(composite); Panel panel = new Panel(new BorderLayout()) { public void update(java.awt.Graphics g) { /* Do not erase the background */ paint(g); } }; frame.add(panel); JRootPane root = new JRootPane(); panel.add(root); java.awt.Container contentPane = root.getContentPane(); /* Creating components */ int nrows = 1000, ncolumns = 10; Vector rows = new Vector(); for (int i = 0; i < nrows; i++) { Vector row = new Vector(); for (int j = 0; j < ncolumns; j++) { row.addElement("Item " + i + "-" + j); } rows.addElement(row); } Vector columns = new Vector(); for (int i = 0; i < ncolumns; i++) { columns.addElement("Column " + i); } JTable table = new JTable(rows, columns); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.createDefaultColumnsFromModel(); JScrollPane scrollPane = new JScrollPane(table); contentPane.setLayout(new BorderLayout()); contentPane.add(scrollPane); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet313.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 313"); shell.setLayout(new FormLayout()); final Button button = new Button(shell, SWT.PUSH); button.setText(">>"); FormData data = new FormData(); data.top = new FormAttachment(0, 4); data.right = new FormAttachment(100, -4); button.setLayoutData(data);//www . j a v a 2 s .c o m final Composite composite = new Composite(shell, SWT.BORDER); final FormData down = new FormData(); down.top = new FormAttachment(button, 4, SWT.BOTTOM); down.bottom = new FormAttachment(100, -4); down.left = new FormAttachment(0, 4); down.right = new FormAttachment(100, -4); final FormData up = new FormData(); up.top = new FormAttachment(0); up.bottom = new FormAttachment(0); up.left = new FormAttachment(0); up.right = new FormAttachment(0); composite.setLayoutData(up); button.addSelectionListener(widgetSelectedAdapter(e -> { if (composite.getLayoutData() == up) { composite.setLayoutData(down); button.setText("<<"); } else { composite.setLayoutData(up); button.setText(">>"); } shell.pack(); })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }