List of usage examples for org.eclipse.swt.widgets ScrollBar setThumb
public void setThumb(int thumb)
From source file:org.eclipse.swt.snippets.Snippet9.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL); shell.setText("Snippet 9"); final Composite composite = new Composite(shell, SWT.BORDER); composite.setSize(700, 600);//from www . j a va 2s .c o m final Color red = display.getSystemColor(SWT.COLOR_RED); composite.addPaintListener(e -> { e.gc.setBackground(red); e.gc.fillOval(5, 5, 690, 590); }); final ScrollBar hBar = shell.getHorizontalBar(); hBar.addListener(SWT.Selection, e -> { Point location = composite.getLocation(); location.x = -hBar.getSelection(); composite.setLocation(location); }); final ScrollBar vBar = shell.getVerticalBar(); vBar.addListener(SWT.Selection, e -> { Point location = composite.getLocation(); location.y = -vBar.getSelection(); composite.setLocation(location); }); shell.addListener(SWT.Resize, e -> { Point size = composite.getSize(); Rectangle rect = shell.getClientArea(); hBar.setMaximum(size.x); vBar.setMaximum(size.y); hBar.setThumb(Math.min(size.x, rect.width)); vBar.setThumb(Math.min(size.y, rect.height)); int hPage = size.x - rect.width; int vPage = size.y - rect.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); Point location = composite.getLocation(); if (hSelection >= hPage) { if (hPage <= 0) hSelection = 0; location.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; location.y = -vSelection; } composite.setLocation(location); }); shell.setSize(600, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet9.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL); final Composite composite = new Composite(shell, SWT.BORDER); composite.setSize(200, 400);/* w w w .j a va2s . c o m*/ final ScrollBar hBar = shell.getHorizontalBar(); hBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Point location = composite.getLocation(); location.x = -hBar.getSelection(); composite.setLocation(location); } }); final ScrollBar vBar = shell.getVerticalBar(); vBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Point location = composite.getLocation(); location.y = -vBar.getSelection(); composite.setLocation(location); } }); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Point size = composite.getSize(); Rectangle rect = shell.getClientArea(); hBar.setMaximum(size.x); vBar.setMaximum(size.y); hBar.setThumb(Math.min(size.x, rect.width)); vBar.setThumb(Math.min(size.y, rect.height)); int hPage = size.x - rect.width; int vPage = size.y - rect.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); Point location = composite.getLocation(); if (hSelection >= hPage) { if (hPage <= 0) hSelection = 0; location.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; location.y = -vSelection; } composite.setLocation(location); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet48.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 48"); shell.setLayout(new FillLayout()); Image originalImage = null;/*from w w w .ja va2s. c o m*/ FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setText("Open an image file or cancel"); String string = dialog.open(); if (string != null) { originalImage = new Image(display, string); } if (originalImage == null) { int width = 150, height = 200; originalImage = new Image(display, width, height); GC gc = new GC(originalImage); gc.fillRectangle(0, 0, width, height); gc.drawLine(0, 0, width, height); gc.drawLine(0, height, width, 0); gc.drawText("Default Image", 10, 10); gc.dispose(); } final Image image = originalImage; final Point origin = new Point(0, 0); final Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); final ScrollBar hBar = canvas.getHorizontalBar(); hBar.addListener(SWT.Selection, e -> { int hSelection = hBar.getSelection(); int destX = -hSelection - origin.x; Rectangle rect = image.getBounds(); canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); origin.x = -hSelection; }); final ScrollBar vBar = canvas.getVerticalBar(); vBar.addListener(SWT.Selection, e -> { int vSelection = vBar.getSelection(); int destY = -vSelection - origin.y; Rectangle rect = image.getBounds(); canvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); origin.y = -vSelection; }); canvas.addListener(SWT.Resize, e -> { Rectangle rect = image.getBounds(); Rectangle client = canvas.getClientArea(); hBar.setMaximum(rect.width); vBar.setMaximum(rect.height); hBar.setThumb(Math.min(rect.width, client.width)); vBar.setThumb(Math.min(rect.height, client.height)); int hPage = rect.width - client.width; int vPage = rect.height - client.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); if (hSelection >= hPage) { if (hPage <= 0) hSelection = 0; origin.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; origin.y = -vSelection; } canvas.redraw(); }); canvas.addListener(SWT.Paint, e -> { GC gc = e.gc; gc.drawImage(image, origin.x, origin.y); Rectangle rect = image.getBounds(); Rectangle client = canvas.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } }); Rectangle rect = image.getBounds(); shell.setSize(Math.max(200, rect.width - 100), Math.max(150, rect.height - 100)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } originalImage.dispose(); display.dispose(); }
From source file:Snippet48.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); Image originalImage = null;//w w w .java 2 s.c o m FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setText("Open an image file or cancel"); String string = dialog.open(); if (string != null) { originalImage = new Image(display, string); } if (originalImage == null) { int width = 150, height = 200; originalImage = new Image(display, width, height); GC gc = new GC(originalImage); gc.fillRectangle(0, 0, width, height); gc.drawLine(0, 0, width, height); gc.drawLine(0, height, width, 0); gc.drawText("Default Image", 10, 10); gc.dispose(); } final Image image = originalImage; final Point origin = new Point(0, 0); final ScrollBar hBar = shell.getHorizontalBar(); hBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { int hSelection = hBar.getSelection(); int destX = -hSelection - origin.x; Rectangle rect = image.getBounds(); shell.scroll(destX, 0, 0, 0, rect.width, rect.height, false); origin.x = -hSelection; } }); final ScrollBar vBar = shell.getVerticalBar(); vBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { int vSelection = vBar.getSelection(); int destY = -vSelection - origin.y; Rectangle rect = image.getBounds(); shell.scroll(0, destY, 0, 0, rect.width, rect.height, false); origin.y = -vSelection; } }); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Rectangle rect = image.getBounds(); Rectangle client = shell.getClientArea(); hBar.setMaximum(rect.width); vBar.setMaximum(rect.height); hBar.setThumb(Math.min(rect.width, client.width)); vBar.setThumb(Math.min(rect.height, client.height)); int hPage = rect.width - client.width; int vPage = rect.height - client.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); if (hSelection >= hPage) { if (hPage <= 0) hSelection = 0; origin.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; origin.y = -vSelection; } shell.redraw(); } }); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event e) { GC gc = e.gc; gc.drawImage(image, origin.x, origin.y); Rectangle rect = image.getBounds(); Rectangle client = shell.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } } }); shell.setSize(200, 150); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ImageScrollFlickerFree.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Image originalImage = null;// w ww .java 2 s. c o m FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setText("Open an image file or cancel"); String string = dialog.open(); if (string != null) { originalImage = new Image(display, string); } if (originalImage == null) { int width = 150, height = 200; originalImage = new Image(display, width, height); GC gc = new GC(originalImage); gc.fillRectangle(0, 0, width, height); gc.drawLine(0, 0, width, height); gc.drawLine(0, height, width, 0); gc.drawText("Default Image", 10, 10); gc.dispose(); } final Image image = originalImage; final Point origin = new Point(0, 0); final Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); final ScrollBar hBar = canvas.getHorizontalBar(); hBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { int hSelection = hBar.getSelection(); int destX = -hSelection - origin.x; Rectangle rect = image.getBounds(); canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); origin.x = -hSelection; } }); final ScrollBar vBar = canvas.getVerticalBar(); vBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { int vSelection = vBar.getSelection(); int destY = -vSelection - origin.y; Rectangle rect = image.getBounds(); canvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); origin.y = -vSelection; } }); canvas.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Rectangle rect = image.getBounds(); Rectangle client = canvas.getClientArea(); hBar.setMaximum(rect.width); vBar.setMaximum(rect.height); hBar.setThumb(Math.min(rect.width, client.width)); vBar.setThumb(Math.min(rect.height, client.height)); int hPage = rect.width - client.width; int vPage = rect.height - client.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); if (hSelection >= hPage) { if (hPage <= 0) hSelection = 0; origin.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; origin.y = -vSelection; } canvas.redraw(); } }); canvas.addListener(SWT.Paint, new Listener() { public void handleEvent(Event e) { GC gc = e.gc; gc.drawImage(image, origin.x, origin.y); Rectangle rect = image.getBounds(); Rectangle client = canvas.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } } }); shell.setSize(200, 150); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } originalImage.dispose(); display.dispose(); }
From source file:ImageAnalyzer.java
void resizeScrollBars() { // Set the max and thumb for the image canvas scroll bars. ScrollBar horizontal = imageCanvas.getHorizontalBar(); ScrollBar vertical = imageCanvas.getVerticalBar(); Rectangle canvasBounds = imageCanvas.getClientArea(); int width = Math.round(imageData.width * xscale); if (width > canvasBounds.width) { // The image is wider than the canvas. horizontal.setEnabled(true);//from w ww . j a v a 2s . c om horizontal.setMaximum(width); horizontal.setThumb(canvasBounds.width); horizontal.setPageIncrement(canvasBounds.width); } else { // The canvas is wider than the image. horizontal.setEnabled(false); if (ix != 0) { // Make sure the image is completely visible. ix = 0; imageCanvas.redraw(); } } int height = Math.round(imageData.height * yscale); if (height > canvasBounds.height) { // The image is taller than the canvas. vertical.setEnabled(true); vertical.setMaximum(height); vertical.setThumb(canvasBounds.height); vertical.setPageIncrement(canvasBounds.height); } else { // The canvas is taller than the image. vertical.setEnabled(false); if (iy != 0) { // Make sure the image is completely visible. iy = 0; imageCanvas.redraw(); } } // Set the max and thumb for the palette canvas scroll bar. vertical = paletteCanvas.getVerticalBar(); if (imageData.palette.isDirect) { vertical.setEnabled(false); } else { // indexed palette canvasBounds = paletteCanvas.getClientArea(); int paletteHeight = imageData.palette.getRGBs().length * 10 + 20; // 10 // pixels // each // index // + 20 // for // margins. vertical.setEnabled(true); vertical.setMaximum(paletteHeight); vertical.setThumb(canvasBounds.height); vertical.setPageIncrement(canvasBounds.height); } }
From source file:org.eclipse.swt.examples.imageanalyzer.ImageAnalyzer.java
void resizeScrollBars() { // Set the max and thumb for the image canvas scroll bars. ScrollBar horizontal = imageCanvas.getHorizontalBar(); ScrollBar vertical = imageCanvas.getVerticalBar(); Rectangle canvasBounds = imageCanvas.getClientArea(); int width = Math.round(imageData.width * xscale); if (width > canvasBounds.width) { // The image is wider than the canvas. horizontal.setEnabled(true);/* ww w . j a v a 2s. c o m*/ horizontal.setMaximum(width); horizontal.setThumb(canvasBounds.width); horizontal.setPageIncrement(canvasBounds.width); } else { // The canvas is wider than the image. horizontal.setEnabled(false); if (ix != 0) { // Make sure the image is completely visible. ix = 0; imageCanvas.redraw(); } } int height = Math.round(imageData.height * yscale); if (height > canvasBounds.height) { // The image is taller than the canvas. vertical.setEnabled(true); vertical.setMaximum(height); vertical.setThumb(canvasBounds.height); vertical.setPageIncrement(canvasBounds.height); } else { // The canvas is taller than the image. vertical.setEnabled(false); if (iy != 0) { // Make sure the image is completely visible. iy = 0; imageCanvas.redraw(); } } // Set the max and thumb for the palette canvas scroll bar. vertical = paletteCanvas.getVerticalBar(); if (imageData.palette.isDirect) { vertical.setEnabled(false); } else { // indexed palette canvasBounds = paletteCanvas.getClientArea(); int paletteHeight = imageData.palette.getRGBs().length * 10 + 20; // 10 pixels each index + 20 for margins. vertical.setEnabled(true); vertical.setMaximum(paletteHeight); vertical.setThumb(canvasBounds.height); vertical.setPageIncrement(canvasBounds.height); } }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createImageTransfer(Composite copyParent, Composite pasteParent) { final Image[] copyImage = new Image[] { null }; Label l = new Label(copyParent, SWT.NONE); l.setText("ImageTransfer:"); //$NON-NLS-1$ GridData data = new GridData(); data.verticalSpan = 2;// w w w . j a va 2s. c o m l.setLayoutData(data); final Canvas copyImageCanvas = new Canvas(copyParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.verticalSpan = 2; data.widthHint = HSIZE; data.heightHint = VSIZE; copyImageCanvas.setLayoutData(data); final Point copyOrigin = new Point(0, 0); final ScrollBar copyHBar = copyImageCanvas.getHorizontalBar(); copyHBar.setEnabled(false); copyHBar.addListener(SWT.Selection, e -> { if (copyImage[0] != null) { int hSelection = copyHBar.getSelection(); int destX = -hSelection - copyOrigin.x; Rectangle rect = copyImage[0].getBounds(); copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); copyOrigin.x = -hSelection; } }); final ScrollBar copyVBar = copyImageCanvas.getVerticalBar(); copyVBar.setEnabled(false); copyVBar.addListener(SWT.Selection, e -> { if (copyImage[0] != null) { int vSelection = copyVBar.getSelection(); int destY = -vSelection - copyOrigin.y; Rectangle rect = copyImage[0].getBounds(); copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); copyOrigin.y = -vSelection; } }); copyImageCanvas.addListener(SWT.Paint, e -> { if (copyImage[0] != null) { GC gc = e.gc; gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y); Rectangle rect = copyImage[0].getBounds(); Rectangle client = copyImageCanvas.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } gc.dispose(); } }); Button openButton = new Button(copyParent, SWT.PUSH); openButton.setText("Open Image"); openButton.addSelectionListener(widgetSelectedAdapter(e -> { FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setText("Open an image file or cancel"); String string = dialog.open(); if (string != null) { if (copyImage[0] != null) { System.out.println("CopyImage"); copyImage[0].dispose(); } copyImage[0] = new Image(e.display, string); copyVBar.setEnabled(true); copyHBar.setEnabled(true); copyOrigin.x = 0; copyOrigin.y = 0; Rectangle rect = copyImage[0].getBounds(); Rectangle client = copyImageCanvas.getClientArea(); copyHBar.setMaximum(rect.width); copyVBar.setMaximum(rect.height); copyHBar.setThumb(Math.min(rect.width, client.width)); copyVBar.setThumb(Math.min(rect.height, client.height)); copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true); copyVBar.setSelection(0); copyHBar.setSelection(0); copyImageCanvas.redraw(); } })); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> { if (copyImage[0] != null) { status.setText(""); // Fetch ImageData at current zoom and save in the clip-board. clipboard.setContents(new Object[] { copyImage[0].getImageDataAtCurrentZoom() }, new Transfer[] { ImageTransfer.getInstance() }); } else { status.setText("No image to copy"); } })); final Image[] pasteImage = new Image[] { null }; l = new Label(pasteParent, SWT.NONE); l.setText("ImageTransfer:"); final Canvas pasteImageCanvas = new Canvas(pasteParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.widthHint = HSIZE; data.heightHint = VSIZE; pasteImageCanvas.setLayoutData(data); final Point pasteOrigin = new Point(0, 0); final ScrollBar pasteHBar = pasteImageCanvas.getHorizontalBar(); pasteHBar.setEnabled(false); pasteHBar.addListener(SWT.Selection, e -> { if (pasteImage[0] != null) { int hSelection = pasteHBar.getSelection(); int destX = -hSelection - pasteOrigin.x; Rectangle rect = pasteImage[0].getBounds(); pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); pasteOrigin.x = -hSelection; } }); final ScrollBar pasteVBar = pasteImageCanvas.getVerticalBar(); pasteVBar.setEnabled(false); pasteVBar.addListener(SWT.Selection, e -> { if (pasteImage[0] != null) { int vSelection = pasteVBar.getSelection(); int destY = -vSelection - pasteOrigin.y; Rectangle rect = pasteImage[0].getBounds(); pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); pasteOrigin.y = -vSelection; } }); pasteImageCanvas.addListener(SWT.Paint, e -> { if (pasteImage[0] != null) { GC gc = e.gc; gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y); Rectangle rect = pasteImage[0].getBounds(); Rectangle client = pasteImageCanvas.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } } }); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> { ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance()); if (imageData != null) { if (pasteImage[0] != null) { System.out.println("PasteImage"); pasteImage[0].dispose(); } status.setText(""); // Consume the ImageData at current zoom as-is. pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData)); pasteVBar.setEnabled(true); pasteHBar.setEnabled(true); pasteOrigin.x = 0; pasteOrigin.y = 0; Rectangle rect = pasteImage[0].getBounds(); Rectangle client = pasteImageCanvas.getClientArea(); pasteHBar.setMaximum(rect.width); pasteVBar.setMaximum(rect.height); pasteHBar.setThumb(Math.min(rect.width, client.width)); pasteVBar.setThumb(Math.min(rect.height, client.height)); pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true); pasteVBar.setSelection(0); pasteHBar.setSelection(0); pasteImageCanvas.redraw(); } else { status.setText("No image to paste"); } })); }
From source file:org.eclipse.swt.examples.accessibility.CTable.java
@Override public void setFont(Font value) { checkWidget();//from ww w . ja va2s . c o m Font oldFont = getFont(); super.setFont(value); Font font = getFont(); if (font.equals(oldFont)) return; GC gc = new GC(this); /* recompute the receiver's cached font height and item height values */ fontHeight = gc.getFontMetrics().getHeight(); setItemHeight(Math.max(fontHeight, imageHeight) + 2 * getCellPadding()); Point headerSize = header.getSize(); int newHeaderHeight = Math.max(fontHeight, headerImageHeight) + 2 * getHeaderPadding(); if (headerSize.y != newHeaderHeight) { header.setSize(headerSize.x, newHeaderHeight); } header.setFont(font); /* * Notify all columns and items of the font change so that elements that * use the receiver's font can recompute their cached string widths. */ for (CTableColumn column : columns) { column.updateFont(gc); } for (int i = 0; i < itemsCount; i++) { items[i].updateFont(gc); } gc.dispose(); if (drawCount <= 0 && header.isVisible()) header.redraw(); /* update scrollbars */ if (columns.length == 0) updateHorizontalBar(); ScrollBar vBar = getVerticalBar(); if (vBar != null) { int thumb = (clientArea.height - getHeaderHeight()) / itemHeight; vBar.setThumb(thumb); vBar.setPageIncrement(thumb); topIndex = vBar.getSelection(); vBar.setVisible(thumb < vBar.getMaximum()); } redraw(); }
From source file:org.eclipse.swt.examples.accessibility.CTable.java
void onResize(Event event) { clientArea = getClientArea();//from ww w .j ava 2 s . c o m /* vertical scrollbar */ ScrollBar vBar = getVerticalBar(); if (vBar != null) { int clientHeight = (clientArea.height - getHeaderHeight()) / itemHeight; int thumb = Math.min(clientHeight, itemsCount); vBar.setThumb(thumb); vBar.setPageIncrement(thumb); int index = vBar.getSelection(); if (index != topIndex) { topIndex = index; redraw(); } boolean visible = clientHeight < itemsCount; if (visible != vBar.getVisible()) { vBar.setVisible(visible); clientArea = getClientArea(); } } /* horizontal scrollbar */ ScrollBar hBar = getHorizontalBar(); if (hBar != null) { int hBarMaximum = hBar.getMaximum(); int thumb = Math.min(clientArea.width, hBarMaximum); hBar.setThumb(thumb); hBar.setPageIncrement(thumb); horizontalOffset = hBar.getSelection(); boolean visible = clientArea.width < hBarMaximum; if (visible != hBar.getVisible()) { hBar.setVisible(visible); clientArea = getClientArea(); } } /* header */ int headerHeight = Math.max(fontHeight, headerImageHeight) + 2 * getHeaderPadding(); header.setSize(clientArea.width, headerHeight); /* if this is the focus control but there are no items then the boundary focus ring must be repainted */ if (itemsCount == 0 && isFocusControl()) redraw(); }