public static void sliderTab() { TabItem tab = new TabItem(folder, SWT.CLOSE); tab.setText("Sliders and Progress bars"); tab.setToolTipText("Tied Slider to ProgressBar"); Composite composite = new Composite(folder, SWT.NONE); composite.setLayout(new GridLayout(2, true)); final Slider slider = new Slider(composite, SWT.HORIZONTAL); final ProgressBar progress = new ProgressBar(composite, SWT.HORIZONTAL); slider.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { progress.setSelection(slider.getSelection()); } }); tab.setControl(composite); }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Slider slider = new Slider(shell, SWT.HORIZONTAL); Rectangle clientArea = shell.getClientArea(); slider.setBounds(clientArea.x + 10, clientArea.y + 10, 200, 32); slider.addListener( SWT.Selection, event -> { String string = "SWT.NONE"; switch (event.detail) { case SWT.DRAG: string = "SWT.DRAG"; break; case SWT.HOME: string = "SWT.HOME"; break; case SWT.END: string = "SWT.END"; break; case SWT.ARROW_DOWN: string = "SWT.ARROW_DOWN"; break; case SWT.ARROW_UP: string = "SWT.ARROW_UP"; break; case SWT.PAGE_DOWN: string = "SWT.PAGE_DOWN"; break; case SWT.PAGE_UP: string = "SWT.PAGE_UP"; break; } System.out.println("Scroll detail -> " + string); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
/** @see OpenGLTab#createControls(Composite) */ void createControls(Composite composite) { Group movementGroup = new Group(composite, SWT.NONE); movementGroup.setText("Translation"); movementGroup.setLayout(new GridLayout(2, false)); new Label(movementGroup, SWT.NONE).setText("X:"); final Slider xMove = new Slider(movementGroup, SWT.NONE); xMove.setIncrement(1); xMove.setMaximum(12); xMove.setMinimum(0); xMove.setThumb(2); xMove.setPageIncrement(2); xMove.setSelection(5); xMove.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { xPos = xMove.getSelection() - 5; } }); new Label(movementGroup, SWT.NONE).setText("Y:"); final Slider yMove = new Slider(movementGroup, SWT.NONE); yMove.setIncrement(1); yMove.setMaximum(12); yMove.setMinimum(0); yMove.setThumb(2); yMove.setPageIncrement(2); yMove.setSelection(5); yMove.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { yPos = yMove.getSelection() - 5; } }); new Label(movementGroup, SWT.NONE).setText("Z:"); final Slider zMove = new Slider(movementGroup, SWT.NONE); zMove.setIncrement(1); zMove.setMaximum(24); zMove.setMinimum(0); zMove.setThumb(4); zMove.setPageIncrement(2); zMove.setSelection(10); zMove.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { zPos = zMove.getSelection() - 25; } }); Composite fogTypesGroup = new Composite(composite, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; fogTypesGroup.setLayout(layout); fogTypesGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); new Label(fogTypesGroup, SWT.NONE).setText("Fog Types:"); final Combo fogTypeCombo = new Combo(fogTypesGroup, SWT.READ_ONLY); GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); data.grabExcessHorizontalSpace = true; fogTypeCombo.setLayoutData(data); fogTypeCombo.setItems(FOG_NAMES); fogTypeCombo.select(0); new Label(composite, SWT.NONE).setText("Fog Density:"); final Slider fogDensitySlider = new Slider(composite, SWT.NONE); fogDensitySlider.setIncrement(1); fogDensitySlider.setMaximum(32); fogDensitySlider.setMinimum(0); fogDensitySlider.setThumb(2); fogDensitySlider.setPageIncrement(5); fogDensitySlider.setSelection(0); fogDensitySlider.setEnabled(false); fogDensitySlider.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { float fogDensity = ((float) fogDensitySlider.getSelection()) / 100; GL.glFogf(GL.GL_FOG_DENSITY, fogDensity); } }); fogTypeCombo.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { int currentSelection = fogTypeCombo.getSelectionIndex(); // fog type GL.GL_LINEAR does not utilize fogDensity, but the other fog types do fogDensitySlider.setEnabled(currentSelection != 0); GL.glFogf(GL.GL_FOG_MODE, FOG_TYPES[currentSelection]); } }); }