Java Code Examples for javafx.scene.control.ScrollPane#getViewportBounds()
The following examples show how to use
javafx.scene.control.ScrollPane#getViewportBounds() .
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 File: ImagePanel.java From marathonv5 with Apache License 2.0 | 6 votes |
private static void ensureVisible(ScrollPane pane, Node node) { Bounds viewport = pane.getViewportBounds(); double contentHeight = pane.getContent().getBoundsInLocal().getHeight(); double contentWidth = pane.getContent().getBoundsInLocal().getWidth(); double nodeMinY = node.getBoundsInParent().getMinY(); double nodeMaxY = node.getBoundsInParent().getMaxY(); double nodeMinX = node.getBoundsInParent().getMinX(); double nodeMaxX = node.getBoundsInParent().getMaxX(); double viewportMinY = (contentHeight - viewport.getHeight()) * pane.getVvalue(); double viewportMaxY = viewportMinY + viewport.getHeight(); double viewportMinX = (contentWidth - viewport.getWidth()) * pane.getHvalue(); double viewportMaxX = viewportMinX + viewport.getWidth(); if (nodeMinY < viewportMinY) { pane.setVvalue(nodeMinY / (contentHeight - viewport.getHeight())); } else if (nodeMaxY > viewportMaxY) { pane.setVvalue((nodeMaxY - viewport.getHeight()) / (contentHeight - viewport.getHeight())); } if (nodeMinX < viewportMinX) { pane.setHvalue(nodeMinX / (contentWidth - viewport.getWidth())); } else if (nodeMaxX > viewportMaxX) { pane.setHvalue((nodeMaxX - viewport.getWidth()) / (contentWidth - viewport.getWidth())); } }
Example 2
Source File: FXEventQueueDevice.java From marathonv5 with Apache License 2.0 | 6 votes |
protected void ensureVisible(Node target) { ScrollPane scrollPane = getParentScrollPane(target); if (scrollPane == null) { return; } Node content = scrollPane.getContent(); Bounds contentBounds = content.localToScene(content.getBoundsInLocal()); Bounds viewportBounds = scrollPane.getViewportBounds(); Bounds nodeBounds = target.localToScene(target.getBoundsInLocal()); if (scrollPane.contains(nodeBounds.getMinX() - contentBounds.getMinX(), nodeBounds.getMinY() - contentBounds.getMinY())) { return; } double toVScroll = (nodeBounds.getMinY() - contentBounds.getMinY()) * ((scrollPane.getVmax() - scrollPane.getVmin()) / (contentBounds.getHeight() - viewportBounds.getHeight())); scrollPane.setVvalue(toVScroll); double toHScroll = (nodeBounds.getMinX() - contentBounds.getMinX()) * ((scrollPane.getHmax() - scrollPane.getHmin()) / (contentBounds.getWidth() - viewportBounds.getWidth())); scrollPane.setHvalue(toHScroll); }
Example 3
Source File: ScrollPaneSample2.java From marathonv5 with Apache License 2.0 | 6 votes |
private void scrollTo(Node target) { ScrollPane scrollPane = getParentScrollPane(target); if (scrollPane == null) return; Node content = scrollPane.getContent(); Bounds contentBounds = content.localToScene(content.getBoundsInLocal()); Bounds viewportBounds = scrollPane.getViewportBounds(); Bounds nodeBounds = target.localToScene(target.getBoundsInLocal()); double toVScroll = (nodeBounds.getMinY() - contentBounds.getMinY()) * ((scrollPane.getVmax() - scrollPane.getVmin()) / (contentBounds.getHeight() - viewportBounds.getHeight())); if (toVScroll >= scrollPane.getVmin() && toVScroll < scrollPane.getVmax()) scrollPane.setVvalue(toVScroll); double toHScroll = (nodeBounds.getMinX() - contentBounds.getMinX()) * ((scrollPane.getHmax() - scrollPane.getHmin()) / (contentBounds.getWidth() - viewportBounds.getWidth())); if (toHScroll >= scrollPane.getHmin() && toHScroll < scrollPane.getHmax()) scrollPane.setHvalue(toHScroll); }
Example 4
Source File: QuestSplitPanel_Controller.java From Path-of-Leveling with MIT License | 5 votes |
public void requestBorder(){ container.setStyle("-fx-border-color: red;"); // Ugly ugly way to scroll to the box if (container.getParent().getParent().getParent().getParent() instanceof ScrollPane) { ScrollPane parent = (ScrollPane) container.getParent().getParent().getParent().getParent(); Bounds b = parent.getViewportBounds(); parent.setVvalue(container.getLayoutY() * (1 / (((VBox)container.getParent()).getHeight() - b.getHeight()))); } }
Example 5
Source File: FxmlControl.java From MyBox with Apache License 2.0 | 5 votes |
public static void setScrollPane(ScrollPane scrollPane, double xOffset, double yOffset) { final Bounds visibleBounds = scrollPane.getViewportBounds(); double scrollWidth = scrollPane.getContent().getBoundsInParent().getWidth() - visibleBounds.getWidth(); double scrollHeight = scrollPane.getContent().getBoundsInParent().getHeight() - visibleBounds.getHeight(); scrollPane.setHvalue(scrollPane.getHvalue() + xOffset / scrollWidth); scrollPane.setVvalue(scrollPane.getVvalue() + yOffset / scrollHeight); }
Example 6
Source File: DiagramTab.java From JetUML with GNU General Public License v3.0 | 5 votes |
private ViewportProjection getViewportProjection() { ScrollPane scrollPane = (ScrollPane)((BorderPane)getContent()).getCenter(); Bounds bounds = scrollPane.getViewportBounds(); // Because, when the scrollbars are not displayed, the Scrollpane will increase // the viewport size beyond the canvas size, it's necessary to max out the dimensions // at the size of the canvas. int viewportWidth = Math.min((int) bounds.getWidth(), (int) aDiagramCanvas.getWidth()); int viewportHeight = Math.min((int) bounds.getHeight(), (int) aDiagramCanvas.getHeight()); return new ViewportProjection(viewportWidth, viewportHeight, (int) aDiagramCanvas.getWidth(), (int) aDiagramCanvas.getHeight(), scrollPane.getHvalue(), scrollPane.getVvalue()); }
Example 7
Source File: JFXGeometryTools.java From phoebus with Eclipse Public License 1.0 | 3 votes |
/** Get origin of a ScrollPane * * <p>If the content is smaller than the scroll pane, * the upper left corner of the scroll pane will show point (0, 0) * of the content. * * <p>As the content gets larger than the scroll pane, * scroll bars allow panning and this method * then determines which (x, y) of the content is displayed * in the upper left corner of the scroll pane. * * @param scroll_pane {@link ScrollPane} * @return Coordinates content in upper left corner */ public static Point2D getContentOrigin(final ScrollPane scroll_pane) { final Bounds viewport = scroll_pane.getViewportBounds(); final Bounds content = scroll_pane.getContent().getBoundsInLocal(); // Tried contentgetWidth() but note that content.getMinX() may be < 0. // Using content.getMaxX() works in all cases. final double x = (content.getMaxX() - viewport.getWidth()) * scroll_pane.getHvalue(); final double y = (content.getMaxY() - viewport.getHeight()) * scroll_pane.getVvalue(); return new Point2D(x, y); }