Java Code Examples for javax.swing.JComponent#scrollRectToVisible()
The following examples show how to use
javax.swing.JComponent#scrollRectToVisible() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans File: CenteredZoomAnimator.java License: Apache License 2.0 | 5 votes |
@Override public void tick(double progress) { double nextZoom = progress >= 1.0 ? targetZoom : (sourceZoom + progress * (targetZoom - sourceZoom)); Scene scene = getScene(); JComponent view = scene.getView (); if (view != null) { Point viewLocation = view.getVisibleRect ().getLocation(); Dimension viewSize = view.getVisibleRect ().getSize(); Point oldCenter = scene.convertSceneToView (center); ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom); scene.validate (); // HINT - forcing to change preferred size of the JComponent view Point newCenter = scene.convertSceneToView (center); Rectangle viewBounds = view.getVisibleRect(); Point visibleCenter = new Point((int)viewBounds.getCenterX(), (int)viewBounds.getCenterY()); newCenter.x += Math.round((newCenter.x - visibleCenter.x) * progress); newCenter.y += Math.round((newCenter.y - visibleCenter.y) * progress); view.scrollRectToVisible (new Rectangle ( newCenter.x - oldCenter.x + viewLocation.x, newCenter.y - oldCenter.y + viewLocation.y, viewSize.width, viewSize.height )); } else { ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom); } }
Example 2
Source Project: netbeans File: DebuggingViewComponent.java License: Apache License 2.0 | 5 votes |
/** * Restore stored scroll position. */ private void restoreScrollPosition(boolean delayScrollWithMarkingDirtyRegion) { if (visibleTreePosition != null) { JTree tree = getJTree(); if (tree != null) { int row = tree.getRowForPath(visibleTreePosition.getPath()); if (row != -1) { Rectangle bounds = tree.getRowBounds(row); if (bounds != null) { int scrollY = bounds.y - visibleTreePosition.getOffset(); JViewport viewport = mainScrollPane.getViewport(); Rectangle rect = viewport.getViewRect(); rect.y = scrollY; if (!rect.isEmpty()) { JComponent view = (JComponent) viewport.getView(); if (delayScrollWithMarkingDirtyRegion) { RepaintManager.currentManager(viewport).addDirtyRegion( view, rect.x, rect.x, rect.width, rect.height); } ignoreScrollAdjustment = true; try { view.scrollRectToVisible( rect); } finally { ignoreScrollAdjustment = false; } } } } } } }
Example 3
Source Project: openjdk-jdk9 File: ExtendedSatelliteComponent.java License: GNU General Public License v2.0 | 5 votes |
private void moveVisibleRect(Point center) { JComponent component = scene.getView(); if (component == null) { return; } double zoomFactor = scene.getZoomFactor(); Rectangle bounds = scene.getBounds(); Dimension size = getSize(); double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0; double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0; double scale = Math.min(sx, sy); int vw = (int) (scale * bounds.width); int vh = (int) (scale * bounds.height); int vx = (size.width - vw) / 2; int vy = (size.height - vh) / 2; int cx = (int) ((double) (center.x - vx) / scale * zoomFactor); int cy = (int) ((double) (center.y - vy) / scale * zoomFactor); Rectangle visibleRect = component.getVisibleRect(); visibleRect.x = cx - visibleRect.width / 2; visibleRect.y = cy - visibleRect.height / 2; component.scrollRectToVisible(visibleRect); this.repaint(); }
Example 4
Source Project: openjdk-jdk9 File: CustomizablePanAction.java License: GNU General Public License v2.0 | 5 votes |
private boolean pan (Widget widget, Point newLocation) { if (scrollPane == null || scene != widget.getScene ()) return false; newLocation = scene.convertSceneToView (widget.convertLocalToScene (newLocation)); SwingUtilities.convertPointToScreen (newLocation, scene.getView ()); JComponent view = scene.getView (); Rectangle rectangle = view.getVisibleRect (); rectangle.x += lastLocation.x - newLocation.x; rectangle.y += lastLocation.y - newLocation.y; view.scrollRectToVisible (rectangle); lastLocation = newLocation; return true; }
Example 5
Source Project: openjdk-jdk9 File: ExtendedSatelliteComponent.java License: GNU General Public License v2.0 | 5 votes |
private void moveVisibleRect(Point center) { JComponent component = scene.getView(); if (component == null) { return; } double zoomFactor = scene.getZoomFactor(); Rectangle bounds = scene.getBounds(); Dimension size = getSize(); double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0; double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0; double scale = Math.min(sx, sy); int vw = (int) (scale * bounds.width); int vh = (int) (scale * bounds.height); int vx = (size.width - vw) / 2; int vy = (size.height - vh) / 2; int cx = (int) ((double) (center.x - vx) / scale * zoomFactor); int cy = (int) ((double) (center.y - vy) / scale * zoomFactor); Rectangle visibleRect = component.getVisibleRect(); visibleRect.x = cx - visibleRect.width / 2; visibleRect.y = cy - visibleRect.height / 2; component.scrollRectToVisible(visibleRect); }
Example 6
Source Project: i18n-editor File: ResourceField.java License: MIT License | 5 votes |
@Override public void focusGained(FocusEvent e) { JComponent parent = (JComponent)getParent(); Rectangle bounds = new Rectangle(getBounds()); bounds.y -= 35; // add fixed space at the top bounds.height += 70; // add fixed space at the bottom parent.scrollRectToVisible(bounds); }
Example 7
Source Project: netbeans File: DragManager.java License: Apache License 2.0 | 4 votes |
public void scroll(JComponent component) { component.scrollRectToVisible(currentDragRect); }
Example 8
Source Project: netbeans File: ZoomManager.java License: Apache License 2.0 | 4 votes |
/** * Set the zoom factor for the Scene mananged by this ZoomManager * instance. The value represents a percentage (e.g. 100%) and * must be a positive number. Any value outside of the defined * range (<tt>MIN_ZOOM_PERCENT</tt> and <tt>MAX_ZOOM_PERCENT</tt>) * will be forced into that range. * * @param percent the percent value (e.g. 50 for half-size, * 200 for double-size). * @param center the point at which to zoom in and keep centered. */ public void setZoom(int percent, Point center) { if (percent < MIN_ZOOM_PERCENT) { percent = MIN_ZOOM_PERCENT; } else if (percent > MAX_ZOOM_PERCENT) { percent = MAX_ZOOM_PERCENT; } // Find the current center point prior to zooming. Point sceneCenter = scene.convertViewToScene(center); zoomPercentage = percent; // Convert the percent value to the zoom factor Scene is expecting // (a double that acts as the multiplier to the component sizes and // locations, such that 0.5 is 50%, 1.0 is 100%, and 2.0 is 200%. double factor = ((double) percent) / 100.0d; scene.setZoomFactor(factor); // Setting the zoom factor alone is not enough, must force // validation and repainting of the scene for it to work. scene.validate(); scene.repaint(); // Find the new center point and scroll the view after zooming. Point newViewCenter = scene.convertSceneToView(sceneCenter); JComponent view = scene.getView(); Rectangle visRect = view.getVisibleRect(); visRect.x = newViewCenter.x - (center.x - visRect.x); visRect.y = newViewCenter.y - (center.y - visRect.y); Dimension viewSize = view.getSize(); if (visRect.x + visRect.width > viewSize.width) { visRect.x = viewSize.width - visRect.width; } if (visRect.y + visRect.height > viewSize.height) { visRect.y = viewSize.height - visRect.height; } if (visRect.x < 0) { visRect.x = 0; } if (visRect.y < 0) { visRect.y = 0; } view.scrollRectToVisible(visRect); view.revalidate(); view.repaint(); // Notify registered listeners so they may update their state. fireZoomEvent(percent); }
Example 9
Source Project: ramus File: TableViewPreferenciesDialog.java License: GNU General Public License v3.0 | 4 votes |
@Override public void focusGained(FocusEvent e) { JComponent c = (JComponent) e.getComponent(); c.scrollRectToVisible(new Rectangle(0, 0, c.getWidth(), c .getHeight())); }
Example 10
Source Project: beautyeye File: ListDemo.java License: Apache License 2.0 | 4 votes |
public void focusGained(FocusEvent e) { JComponent c = (JComponent)e.getComponent(); c.scrollRectToVisible(new Rectangle(0, 0, c.getWidth(), c.getHeight())); }