|
| 1 | +package net.sf.j2s.test.swt.widgets; |
| 2 | + |
| 3 | +import org.eclipse.swt.SWT; |
| 4 | +import org.eclipse.swt.events.SelectionAdapter; |
| 5 | +import org.eclipse.swt.events.SelectionEvent; |
| 6 | +import org.eclipse.swt.events.SelectionListener; |
| 7 | +import org.eclipse.swt.layout.FillLayout; |
| 8 | +import org.eclipse.swt.layout.GridData; |
| 9 | +import org.eclipse.swt.layout.GridLayout; |
| 10 | +import org.eclipse.swt.widgets.Composite; |
| 11 | +import org.eclipse.swt.widgets.Display; |
| 12 | +import org.eclipse.swt.widgets.Label; |
| 13 | +import org.eclipse.swt.widgets.ScrollBar; |
| 14 | +import org.eclipse.swt.widgets.Shell; |
| 15 | +import org.eclipse.swt.widgets.Slider; |
| 16 | + |
| 17 | +public class TestScrollBar extends Shell { |
| 18 | + |
| 19 | + private Composite composite; |
| 20 | + |
| 21 | + /** |
| 22 | + * Launch the application |
| 23 | + * @param args |
| 24 | + */ |
| 25 | + public static void main(String args[]) { |
| 26 | + try { |
| 27 | + Display display = Display.getDefault(); |
| 28 | + TestScrollBar shell = new TestScrollBar(display, |
| 29 | + SWT.SHELL_TRIM); |
| 30 | + shell.open(); |
| 31 | + shell.layout(); |
| 32 | + while (!shell.isDisposed()) { |
| 33 | + if (!display.readAndDispatch()) |
| 34 | + display.sleep(); |
| 35 | + } |
| 36 | + } catch (Exception e) { |
| 37 | + e.printStackTrace(); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Create the shell |
| 43 | + * @param display |
| 44 | + * @param style |
| 45 | + */ |
| 46 | + public TestScrollBar(Display display, int style) { |
| 47 | + super(display, style); |
| 48 | + createContents(); |
| 49 | + setLayout(new FillLayout()); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Create contents of the window |
| 54 | + */ |
| 55 | + protected void createContents() { |
| 56 | + setText("SWT Application"); |
| 57 | + setSize(500, 375); |
| 58 | + |
| 59 | + composite = new Composite(this, SWT.NONE); |
| 60 | + GridLayout gridLayout = new GridLayout(); |
| 61 | + gridLayout.horizontalSpacing = 0; |
| 62 | + gridLayout.numColumns = 2; |
| 63 | + composite.setLayout(gridLayout); |
| 64 | + composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 65 | + |
| 66 | + Composite composite_1 = new Composite(composite, SWT.V_SCROLL); |
| 67 | + composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 68 | + composite_1.setLayout(new GridLayout()); |
| 69 | + |
| 70 | + composite_1 = new Composite(composite, SWT.H_SCROLL); |
| 71 | + composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 72 | + composite_1.setLayout(new GridLayout()); |
| 73 | + |
| 74 | + final Composite composite_2 = new Composite(composite, SWT.H_SCROLL | SWT.V_SCROLL); |
| 75 | + composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 76 | + composite_2.setLayout(new GridLayout()); |
| 77 | + |
| 78 | + composite_2.getVerticalBar().addSelectionListener(new SelectionAdapter() { |
| 79 | + |
| 80 | + @Override |
| 81 | + public void widgetSelected(SelectionEvent e) { |
| 82 | + System.out.println(composite_2.getVerticalBar().getSelection()); |
| 83 | + } |
| 84 | + |
| 85 | + }); |
| 86 | + |
| 87 | + composite_2.getVerticalBar().setSelection(80); |
| 88 | + //composite_2.getHorizontalBar().setSelection(80); |
| 89 | + composite_2.getHorizontalBar().addSelectionListener(new SelectionAdapter() { |
| 90 | + |
| 91 | + @Override |
| 92 | + public void widgetSelected(SelectionEvent e) { |
| 93 | + System.out.println(composite_2.getHorizontalBar().getSelection()); |
| 94 | + } |
| 95 | + |
| 96 | + }); |
| 97 | + |
| 98 | + composite_2.getHorizontalBar().setMinimum(20); |
| 99 | + |
| 100 | + composite_2.getHorizontalBar().setMaximum(40); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + protected void checkSubclass() { |
| 105 | + // Disable the check that prevents subclassing of SWT components |
| 106 | + } |
| 107 | +} |
0 commit comments