List of usage examples for org.eclipse.swt.custom ScrolledComposite ScrolledComposite
public ScrolledComposite(Composite parent, int style)
From source file:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell shell = new Shell(d); shell.setSize(250, 200);/*from www . j a v a2s . c om*/ shell.setLayout(new FillLayout()); ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite child = new Composite(sc, SWT.NONE); child.setLayout(new FillLayout()); new Button(child, SWT.PUSH).setText("One"); new Button(child, SWT.PUSH).setText("Two"); sc.setContent(child); sc.setMinSize(300, 300); sc.setExpandHorizontal(true); sc.setExpandVertical(true); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:ScrollCompisiteHoriVertical.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SashForm Test"); shell.setLayout(new FillLayout()); // Create the ScrolledComposite to scroll horizontally and vertically ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite child = new Composite(sc, SWT.NONE); child.setLayout(new FillLayout()); new Button(child, SWT.PUSH).setText("One"); new Button(child, SWT.PUSH).setText("Two"); child.setSize(400, 400);//from ww w . j a va2 s.co m sc.setContent(child); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ScrolledCompositeMiniSize.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SashForm Test"); shell.setLayout(new FillLayout()); // Create the ScrolledComposite to scroll horizontally and vertically ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite child = new Composite(sc, SWT.NONE); child.setLayout(new FillLayout()); new Button(child, SWT.PUSH).setText("One"); new Button(child, SWT.PUSH).setText("Two"); sc.setMinSize(400, 400);/*ww w . ja va2s . co m*/ // Expand both horizontally and vertically sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setContent(child); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet5.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // this button is always 400 x 400. Scrollbars appear if the window is // resized to be // too small to show part of the button ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b1 = new Button(c1, SWT.PUSH); b1.setText("fixed size button"); b1.setSize(400, 400);//from w w w .j av a 2s . co m c1.setContent(b1); // this button has a minimum size of 400 x 400. If the window is resized // to be big // enough to show more than 400 x 400, the button will grow in size. If // the window // is made too small to show 400 x 400, scrollbars will appear. ScrolledComposite c2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b2 = new Button(c2, SWT.PUSH); b2.setText("expanding button"); c2.setContent(b2); c2.setExpandHorizontal(true); c2.setExpandVertical(true); c2.setMinWidth(400); c2.setMinHeight(400); shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
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 w w w . j a v a 2 s . com 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.Snippet5.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 5"); shell.setLayout(new FillLayout()); // this button is always 400 x 400. Scrollbars appear if the window is resized to be // too small to show part of the button ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b1 = new Button(c1, SWT.PUSH); b1.setText("fixed size button"); b1.setSize(400, 400);/*from w ww . ja v a2 s . c o m*/ c1.setContent(b1); // this button has a minimum size of 400 x 400. If the window is resized to be big // enough to show more than 400 x 400, the button will grow in size. If the window // is made too small to show 400 x 400, scrollbars will appear. ScrolledComposite c2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b2 = new Button(c2, SWT.PUSH); b2.setText("expanding button"); c2.setContent(b2); c2.setExpandHorizontal(true); c2.setExpandVertical(true); c2.setMinSize(400, 400); shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet167.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 167"); shell.setLayout(new FillLayout()); final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button1 = new Button(sc1, SWT.PUSH); button1.setText("Button 1"); button1.setSize(400, 300);/*from w ww . j a va 2 s .c o m*/ sc1.setContent(button1); final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button2 = new Button(sc2, SWT.PUSH); button2.setText("Button 2"); button2.setSize(300, 400); sc2.setContent(button2); final ScrollBar vBar1 = sc1.getVerticalBar(); final ScrollBar vBar2 = sc2.getVerticalBar(); final ScrollBar hBar1 = sc1.getHorizontalBar(); final ScrollBar hBar2 = sc2.getHorizontalBar(); SelectionListener listener1 = widgetSelectedAdapter(e -> { int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb()); int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb()); sc2.setOrigin(x, y); }); SelectionListener listener2 = widgetSelectedAdapter(e -> { int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb()); int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb()); sc1.setOrigin(x, y); }); vBar1.addSelectionListener(listener1); hBar1.addSelectionListener(listener1); vBar2.addSelectionListener(listener2); hBar2.addSelectionListener(listener2); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScollCompositeControl.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // this button is always 400 x 400. Scrollbars appear if the window is // resized to be // too small to show part of the button ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b1 = new Button(c1, SWT.PUSH); b1.setText("fixed size button"); b1.setSize(400, 400);//from w w w. ja v a 2 s. co m c1.setContent(b1); shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet296.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 296"); shell.setBounds(10, 10, 300, 300);/*from www.ja v a 2 s. c o m*/ final ScrolledComposite sc = new ScrolledComposite(shell, SWT.VERTICAL); sc.setBounds(10, 10, 280, 200); final int clientWidth = sc.getClientArea().width; final Tree tree = new Tree(sc, SWT.NONE); for (int i = 0; i < 99; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("item " + i); new TreeItem(item, SWT.NONE).setText("child"); } sc.setContent(tree); int prefHeight = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; tree.setSize(clientWidth, prefHeight); /* * The following listener ensures that the Tree is always large * enough to not need to show its own vertical scrollbar. */ tree.addTreeListener(new TreeListener() { @Override public void treeExpanded(TreeEvent e) { int prefHeight = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; tree.setSize(clientWidth, prefHeight); } @Override public void treeCollapsed(TreeEvent e) { int prefHeight = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; tree.setSize(clientWidth, prefHeight); } }); /* * The following listener ensures that a newly-selected item * in the Tree is always visible. */ tree.addSelectionListener(widgetSelectedAdapter(e -> { TreeItem[] selectedItems = tree.getSelection(); if (selectedItems.length > 0) { Rectangle itemRect = selectedItems[0].getBounds(); Rectangle area = sc.getClientArea(); Point origin = sc.getOrigin(); if (itemRect.x < origin.x || itemRect.y < origin.y || itemRect.x + itemRect.width > origin.x + area.width || itemRect.y + itemRect.height > origin.y + area.height) { sc.setOrigin(itemRect.x, itemRect.y); } } })); /* * The following listener scrolls the Tree one item at a time * in response to MouseWheel events. */ tree.addListener(SWT.MouseWheel, event -> { Point origin = sc.getOrigin(); if (event.count < 0) { origin.y = Math.min(origin.y + tree.getItemHeight(), tree.getSize().y); } else { origin.y = Math.max(origin.y - tree.getItemHeight(), 0); } sc.setOrigin(origin); }); Button downButton = new Button(shell, SWT.PUSH); downButton.setBounds(10, 220, 120, 30); downButton.setText("Down 10px"); downButton.addListener(SWT.Selection, event -> sc.setOrigin(0, sc.getOrigin().y + 10)); Button upButton = new Button(shell, SWT.PUSH); upButton.setBounds(140, 220, 120, 30); upButton.setText("Up 10px"); upButton.addListener(SWT.Selection, event -> sc.setOrigin(0, sc.getOrigin().y - 10)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScrollBarSelectionListener.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button1 = new Button(sc1, SWT.PUSH); button1.setText("Button 1"); button1.setSize(400, 300);/* ww w . j a v a2s. c o m*/ sc1.setContent(button1); final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button2 = new Button(sc2, SWT.PUSH); button2.setText("Button 2"); button2.setSize(300, 400); sc2.setContent(button2); final ScrollBar vBar1 = sc1.getVerticalBar(); final ScrollBar vBar2 = sc2.getVerticalBar(); final ScrollBar hBar1 = sc1.getHorizontalBar(); final ScrollBar hBar2 = sc2.getHorizontalBar(); SelectionListener listener1 = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb()); int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb()); sc2.setOrigin(x, y); } }; SelectionListener listener2 = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb()); int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb()); sc1.setOrigin(x, y); } }; vBar1.addSelectionListener(listener1); hBar1.addSelectionListener(listener1); vBar2.addSelectionListener(listener2); hBar2.addSelectionListener(listener2); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }