javafx.scene.control.ScrollBar Java Examples

The following examples show how to use javafx.scene.control.ScrollBar. 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: FxTable.java    From FxDock with Apache License 2.0 6 votes vote down vote up
protected void fixHorizontalScrollbar()
{
	for(Node n: lookupAll(".scroll-bar"))
	{
		if(n instanceof ScrollBar)
		{
			ScrollBar b = (ScrollBar)n;
			if(b.getOrientation() == Orientation.HORIZONTAL)
			{
				if(isAutoResizeMode())
				{
					b.setManaged(false);
					b.setPrefHeight(0);
					b.setPrefWidth(0);
				}
				else
				{
					b.setManaged(true);
					b.setPrefHeight(USE_COMPUTED_SIZE);
					b.setPrefWidth(USE_COMPUTED_SIZE);
				}
			}
		}
	}
}
 
Example #2
Source File: FileBrowseService.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
private void restoreTreeScrollState() {

        threadService.schedule(() -> { // run after some ms
            threadService.runActionLater(() -> { // run in ui thread

                Set<Node> nodes = this.treeView.lookupAll(".scroll-bar");
                for (Node node : nodes) {
                    ScrollBar scrollBar = (ScrollBar) node;
                    if (scrollBar.getOrientation() == Orientation.VERTICAL) {
                        verticalScrollState.restoreState(scrollBar);
                    } else if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
                        horizontalScrollState.restoreState(scrollBar);
                    }
                }
            });
        }, 50, TimeUnit.MILLISECONDS);
    }
 
Example #3
Source File: FileBrowseService.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
private void initializeScrollListener() {
    threadService.runActionLater(() -> {
        this.treeView = controller.getFileSystemView();

        Set<Node> nodes = this.treeView.lookupAll(".scroll-bar");
        for (Node node : nodes) {
            ScrollBar scrollBar = (ScrollBar) node;
            if (scrollBar.getOrientation() == Orientation.VERTICAL) {
                verticalScrollState.updateState(scrollBar);
                scrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
                    verticalScrollState.updateState(scrollBar, newValue);
                });
            } else if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
                horizontalScrollState.updateState(scrollBar);
                scrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
                    horizontalScrollState.updateState(scrollBar, newValue);
                });
            }
        }
    });
}
 
Example #4
Source File: PrettyScrollPane.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private void bindScrollBars() {
  final Set<Node> nodes = lookupAll("ScrollBar");
  for (Node node : nodes) {
    if (node instanceof ScrollBar) {
      ScrollBar bar = (ScrollBar) node;
      if (bar.getOrientation().equals(Orientation.VERTICAL)) {
        bindScrollBars(verticalScrollBar, bar);
      } else if (bar.getOrientation().equals(Orientation.HORIZONTAL)) {
        bindScrollBars(horizontalScrollBar, bar);
      }
    }
  }
}
 
Example #5
Source File: OnlyScrollPaneSkin.java    From oim-fx with MIT License 5 votes vote down vote up
/**
 * Computes the size that should be reserved for horizontal scrollbar in
 * size hints (min/pref height)
 */
private double computeHsbSizeHint(ScrollPane sp) {
	return ((sp.getHbarPolicy() == ScrollBarPolicy.ALWAYS) ||
			(sp.getHbarPolicy() == ScrollBarPolicy.AS_NEEDED && (sp.getPrefViewportHeight() > 0 || sp.getMinViewportHeight() > 0)))
					? hsb.prefHeight(ScrollBar.USE_COMPUTED_SIZE)
					: 0;
}
 
Example #6
Source File: ScrollState.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
public void restoreState(ScrollBar scrollBar) {
    if (value > 0) {
        updateState(scrollBar);
        scrollBar.setMin(getMin());
        scrollBar.setMax(getMax());
        scrollBar.setUnitIncrement(getUnitIncrement());
        scrollBar.setBlockIncrement(getBlockIncrement());
        scrollBar.setValue(value);
    }
}
 
Example #7
Source File: ScrollState.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
public void updateState(ScrollBar scrollBar, Number newValue) {
    if (Objects.nonNull(newValue)) {
        double value = newValue.doubleValue();
        if (value > 0) {
            updateState(scrollBar);
            this.setValue(value);
        }
    }
}
 
Example #8
Source File: VirtualizedScrollPane.java    From Flowless with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void setupUnitIncrement(ScrollBar bar) {
    bar.unitIncrementProperty().bind(new DoubleBinding() {
        { bind(bar.maxProperty(), bar.visibleAmountProperty()); }

        @Override
        protected double computeValue() {
            double max = bar.getMax();
            double visible = bar.getVisibleAmount();
            return max > visible
                    ? 16 / (max - visible) * max
                    : 0;
        }
    });
}
 
Example #9
Source File: PanelMenuCreator.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public MenuItem createRightPanelMenuItem() {
    MenuItem createRight = new MenuItem("Create");
    createRight.setOnAction(e -> {
        logger.info("Menu: Panels > Create");
        panelControl.createNewPanelAtEnd();
        // listener is used as panelsScroll's Hmax property doesn't update
        // synchronously
        ChangeListener<Number> listener = new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
                for (Node child : panelsScrollPane.getChildrenUnmodifiable()) {
                    if (child instanceof ScrollBar) {
                        ScrollBar scrollBar = (ScrollBar) child;
                        if (scrollBar.getOrientation() == Orientation.HORIZONTAL
                                && scrollBar.visibleProperty().get()) {
                            panelControl.scrollToCurrentlySelectedPanel();
                            break;
                        }
                    }
                }
                panelControl.widthProperty().removeListener(this);
            }
        };
        panelControl.widthProperty().addListener(listener);
    });
    createRight.setAccelerator(CREATE_RIGHT_PANEL);
    return createRight;
}
 
Example #10
Source File: GUIUtil.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static double getScrollbarWidth(Node scrollablePane) {
    Node node = scrollablePane.lookup(".scroll-bar");
    if (node instanceof ScrollBar) {
        final ScrollBar bar = (ScrollBar) node;
        if (bar.getOrientation().equals(Orientation.VERTICAL))
            return bar.getWidth();
    }
    return 0;
}
 
Example #11
Source File: Exercise_20_09.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	MultipleBallPane ballPane = new MultipleBallPane();
	ballPane.setStyle("-fx-border-color: yellow");

	Button btAdd = new Button("+");
	Button btSubtract = new Button("-");
	HBox hBox = new HBox(10);
	hBox.getChildren().addAll(btAdd, btSubtract);
	hBox.setAlignment(Pos.CENTER);

	// Add or remove a ball
	btAdd.setOnAction(e -> ballPane.add());
	btSubtract.setOnAction(e -> ballPane.subtract());

	// Pause and resume animation
	ballPane.setOnMousePressed(e -> ballPane.pause());
	ballPane.setOnMouseReleased(e -> ballPane.play());

	// Use a scroll bar to control animation speed
	ScrollBar sbSpeed = new ScrollBar();
	sbSpeed.setMax(20);
	sbSpeed.setValue(10);
	ballPane.rateProperty().bind(sbSpeed.valueProperty());

	BorderPane pane = new BorderPane();
	pane.setCenter(ballPane);
	pane.setTop(sbSpeed);
	pane.setBottom(hBox);

	// Create a scene and place the in the stage
	Scene scene = new Scene(pane, 250, 150);
	primaryStage.setTitle("Exercise_20_09"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example #12
Source File: Utils.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static ScrollBar findScrollBar(Node node, Orientation orientation) {
	Set<Node> scrollBars = node.lookupAll(".scroll-bar");
	for (Node scrollBar : scrollBars) {
		if (scrollBar instanceof ScrollBar &&
			((ScrollBar)scrollBar).getOrientation() == orientation)
		  return (ScrollBar) scrollBar;
	}
	return null;
}
 
Example #13
Source File: JFXListBoxSelect.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Float getScrollWidth() {
	if( this.scrollWidth == null ) {
		ScrollBar scrollBar = new ScrollBar();
		scrollBar.setManaged(false);
		scrollBar.applyCss();
		
		this.scrollWidth = Double.valueOf(scrollBar.getWidth()).floatValue();
	}
	return this.scrollWidth;
}
 
Example #14
Source File: ScenarioConfigEditorFX.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
void scrolled(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
	double value = newValue.doubleValue();
	// System.out.println("Scrolled to " + value);
	ScrollBar bar = getVerticalScrollbar(tableView);
	if (value == bar.getMax()) {
		// System.out.println("Adding new persons.");
		// double targetValue = value * items.size();
		// addPersons();
		// bar.setValue(targetValue / items.size());
	}
}
 
Example #15
Source File: ScenarioConfigEditorFX.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private ScrollBar getVerticalScrollbar(TableView<?> table) {
	ScrollBar result = null;
	for (Node n : table.lookupAll(".scroll-bar")) {
		if (n instanceof ScrollBar) {
			ScrollBar bar = (ScrollBar) n;
			if (bar.getOrientation().equals(Orientation.VERTICAL)) {
				result = bar;
			}
		}
	}
	return result;
}
 
Example #16
Source File: FxTreeTable.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected void fixHorizontalScrollbar()
{
	Skin skin = tree.getSkin();
	if(skin == null)
	{
		return;
	}
	
	for(Node n: skin.getNode().lookupAll(".scroll-bar"))
	{
		if(n instanceof ScrollBar)
		{
			ScrollBar b = (ScrollBar)n;
			if(b.getOrientation() == Orientation.HORIZONTAL)
			{
				if(isAutoResizeMode())
				{
					b.setManaged(false);
					b.setPrefHeight(0);
					b.setPrefWidth(0);
				}
				else
				{
					b.setManaged(true);
					b.setPrefHeight(USE_COMPUTED_SIZE);
					b.setPrefWidth(USE_COMPUTED_SIZE);
				}
			}
		}
	}
}
 
Example #17
Source File: OnlyScrollPaneSkin.java    From oim-fx with MIT License 5 votes vote down vote up
/**
 * Computes the size that should be reserved for vertical scrollbar in size
 * hints (min/pref width)
 */
private double computeVsbSizeHint(ScrollPane sp) {
	return ((sp.getVbarPolicy() == ScrollBarPolicy.ALWAYS) ||
			(sp.getVbarPolicy() == ScrollBarPolicy.AS_NEEDED && (sp.getPrefViewportWidth() > 0
					|| sp.getMinViewportWidth() > 0)))
							? vsb.prefWidth(ScrollBar.USE_COMPUTED_SIZE)
							: 0;
}
 
Example #18
Source File: PrettyScrollPane.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private void bindScrollBars(ScrollBar scrollBarA, ScrollBar scrollBarB) {
  scrollBarA.valueProperty().bindBidirectional(scrollBarB.valueProperty());
  scrollBarA.minProperty().bindBidirectional(scrollBarB.minProperty());
  scrollBarA.maxProperty().bindBidirectional(scrollBarB.maxProperty());
  scrollBarA.visibleAmountProperty().bindBidirectional(scrollBarB.visibleAmountProperty());
  scrollBarA.unitIncrementProperty().bindBidirectional(scrollBarB.unitIncrementProperty());
  scrollBarA.blockIncrementProperty().bindBidirectional(scrollBarB.blockIncrementProperty());
}
 
Example #19
Source File: FxmlControl.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static ScrollBar getVScrollBar(WebView webView) {
    try {
        Set<Node> scrolls = webView.lookupAll(".scroll-bar");
        for (Node scrollNode : scrolls) {
            if (ScrollBar.class.isInstance(scrollNode)) {
                ScrollBar scroll = (ScrollBar) scrollNode;
                if (scroll.getOrientation() == Orientation.VERTICAL) {
                    return scroll;
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}
 
Example #20
Source File: FXUtilities.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find the scrollbar of the given table.
 *
 * @param node
 * @return
 */
public static ScrollBar findScrollBar(Node node, Orientation orientation) {
    Set<Node> below = node.lookupAll(".scroll-bar");
    for (final Node nodeBelow : below) {
        if (nodeBelow instanceof ScrollBar) {
            ScrollBar sb = (ScrollBar) nodeBelow;
            if (sb.getOrientation() == orientation) {
                return sb;
            }
        }
    }
    return null;
}
 
Example #21
Source File: FXUtilities.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * bidirectionally bind scroll bars of two nodes
 *
 * @param node1
 * @param node2
 * @param orientation
 */
public static void bidirectionallyBindScrollBars(final Node node1, final Node node2, Orientation orientation) {
    final ScrollBar scrollBar1 = findScrollBar(node1, orientation);
    final ScrollBar scrollBar2 = findScrollBar(node2, orientation);

    if (scrollBar1 != null && scrollBar2 != null) {
        final Single<Boolean> inChange = new Single<>(false);
        scrollBar1.valueProperty().addListener(observable -> {
            if (!inChange.get()) {
                try {
                    inChange.set(true);
                    scrollBar2.setValue(scrollBar1.getValue() * (scrollBar2.getMax() - scrollBar2.getMin()) / (scrollBar1.getMax() - scrollBar1.getMin()));
                } finally {
                    inChange.set(false);
                }
            }
        });
        scrollBar2.valueProperty().addListener(observable -> {
            if (!inChange.get()) {
                try {
                    inChange.set(true);
                    scrollBar1.setValue(scrollBar2.getValue() * (scrollBar1.getMax() - scrollBar1.getMin()) / (scrollBar2.getMax() - scrollBar2.getMin()));
                } finally {
                    inChange.set(false);
                }
            }
        });
    }
}
 
Example #22
Source File: KeyTestingController.java    From chvote-1-0 with GNU Affero General Public License v3.0 5 votes vote down vote up
private void bindScrollBars() {
    ScrollBar plainTextScrollBar = plainTextList.lookupAll(".scroll-bar").stream().map(e -> (ScrollBar) e).filter(e -> e.getOrientation().equals(Orientation.HORIZONTAL)).findFirst().orElse(null);
    ScrollBar decryptedTextScrollBar = decryptedTextList.lookupAll(".scroll-bar").stream().map(e -> (ScrollBar) e).filter(e -> e.getOrientation().equals(Orientation.HORIZONTAL)).findFirst().orElse(null);

    if (plainTextScrollBar != null && decryptedTextScrollBar != null) {
        plainTextScrollBar.valueProperty().bindBidirectional(decryptedTextScrollBar.valueProperty());
    } else {
        LOGGER.error("couldn't find scrollbars");
    }
}
 
Example #23
Source File: ScrollBarSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private ScrollBar horizontalScrollBar(double minw, double minh, double prefw, double prefh, double maxw, double maxh) {
    final ScrollBar scrollBar = new ScrollBar();
    scrollBar.setMinSize(minw, minh);
    scrollBar.setPrefSize(prefw, prefh);
    scrollBar.setMaxSize(maxw, maxh);
    scrollBar.setVisibleAmount(50);
    scrollBar.setMax(xBarWidth-(2*circleRadius));
    return scrollBar;
}
 
Example #24
Source File: ScrollBarSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private ScrollBar verticalScrollBar(double minw, double minh, double prefw, double prefh, double maxw, double maxh) {
    final ScrollBar scrollBar = new ScrollBar();
    scrollBar.setMinSize(minw, minh);
    scrollBar.setPrefSize(prefw, prefh);
    scrollBar.setMaxSize(maxw, maxh);
    scrollBar.setVisibleAmount(50);
    scrollBar.setMax(yBarHeight-(2*circleRadius));
    return scrollBar;
}
 
Example #25
Source File: ScrollBarSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private ScrollBar horizontalScrollBar(double minw, double minh, double prefw, double prefh, double maxw, double maxh) {
    final ScrollBar scrollBar = new ScrollBar();
    scrollBar.setMinSize(minw, minh);
    scrollBar.setPrefSize(prefw, prefh);
    scrollBar.setMaxSize(maxw, maxh);
    scrollBar.setVisibleAmount(50);
    scrollBar.setMax(xBarWidth-(2*circleRadius));
    return scrollBar;
}
 
Example #26
Source File: ScrollBarSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private ScrollBar verticalScrollBar(double minw, double minh, double prefw, double prefh, double maxw, double maxh) {
    final ScrollBar scrollBar = new ScrollBar();
    scrollBar.setMinSize(minw, minh);
    scrollBar.setPrefSize(prefw, prefh);
    scrollBar.setMaxSize(maxw, maxh);
    scrollBar.setVisibleAmount(50);
    scrollBar.setMax(yBarHeight-(2*circleRadius));
    return scrollBar;
}
 
Example #27
Source File: InfiniteCanvas.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates the {@link Group} designated for holding the scrollbars and
 * places the scrollbars in it. Furthermore, event listeners are registered
 * to update the scroll offset upon scrollbar movement.
 *
 * @return The {@link Group} designated for holding the scrollbars.
 */
protected Group createScrollBarGroup() {
	// create horizontal scrollbar
	horizontalScrollBar = new ScrollBar();
	horizontalScrollBar.setVisible(false);
	horizontalScrollBar.setOpacity(0.5);

	// create vertical scrollbar
	verticalScrollBar = new ScrollBar();
	verticalScrollBar.setOrientation(Orientation.VERTICAL);
	verticalScrollBar.setVisible(false);
	verticalScrollBar.setOpacity(0.5);

	// bind horizontal size
	DoubleBinding vWidth = new DoubleBinding() {
		{
			bind(verticalScrollBar.visibleProperty(),
					verticalScrollBar.widthProperty());
		}

		@Override
		protected double computeValue() {
			return verticalScrollBar.isVisible()
					? verticalScrollBar.getWidth() : 0;
		}
	};
	horizontalScrollBar.prefWidthProperty()
			.bind(widthProperty().subtract(vWidth));

	// bind horizontal y position
	horizontalScrollBar.layoutYProperty().bind(heightProperty()
			.subtract(horizontalScrollBar.heightProperty()));

	// bind vertical size
	DoubleBinding hHeight = new DoubleBinding() {
		{
			bind(horizontalScrollBar.visibleProperty(),
					horizontalScrollBar.heightProperty());
		}

		@Override
		protected double computeValue() {
			return horizontalScrollBar.isVisible()
					? horizontalScrollBar.getHeight() : 0;
		}
	};
	verticalScrollBar.prefHeightProperty()
			.bind(heightProperty().subtract(hHeight));

	// bind vertical x position
	verticalScrollBar.layoutXProperty().bind(
			widthProperty().subtract(verticalScrollBar.widthProperty()));

	// fade in/out on mouse enter/exit
	registerFadeInOutTransitions(horizontalScrollBar);
	registerFadeInOutTransitions(verticalScrollBar);

	horizontalScrollBar.valueProperty()
			.addListener(horizontalScrollBarValueChangeListener);
	verticalScrollBar.valueProperty()
			.addListener(verticalScrollBarValueChangeListener);

	return new Group(horizontalScrollBar, verticalScrollBar);
}
 
Example #28
Source File: ScrollState.java    From AsciidocFX with Apache License 2.0 4 votes vote down vote up
public void updateState(ScrollBar scrollBar) {
    this.setMin(scrollBar.getMin());
    this.setMax(scrollBar.getMax());
    this.setUnitIncrement(scrollBar.getUnitIncrement());
    this.setBlockIncrement(scrollBar.getBlockIncrement());
}
 
Example #29
Source File: VirtualizedScrollPane.java    From Flowless with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void unbindScrollBar(ScrollBar bar) {
    bar.maxProperty().unbind();
    bar.unitIncrementProperty().unbind();
    bar.blockIncrementProperty().unbind();
    bar.visibleProperty().unbind();
}
 
Example #30
Source File: Exercise_20_05.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	MultipleBallPane ballPane = new MultipleBallPane();
	ballPane.setStyle("-fx-border-color: yellow");

	// Create four buttons
	Button btSuspend = new Button("Suspend");
	Button btResume = new Button("Resume");
	Button btAdd = new Button("+");
	Button btSubtract = new Button("-");
	HBox hBox = new HBox(10);
	hBox.getChildren().addAll(
		btSuspend, btResume, btAdd, btSubtract);
	hBox.setAlignment(Pos.CENTER);

	// Add or remove a ball
	btAdd.setOnAction(e -> ballPane.add());
	btSubtract.setOnAction(e -> ballPane.subtract());
	ballPane.setOnMousePressed(e -> {
		for (Node node: ballPane.getChildren()) {
			Ball ball = (Ball)node;
			if (ball.contains(e.getX(), e.getY())) {
				ballPane.getChildren().remove(ball);
			}
		}
	});

	// Pause and resume animation
	btSuspend.setOnAction(e -> ballPane.pause());
	btResume.setOnAction(e -> ballPane.play());

	// Use a scroll bar to control animation speed
	ScrollBar sbSpeed = new ScrollBar();
	sbSpeed.setMax(20);
	sbSpeed.setValue(10);
	ballPane.rateProperty().bind(sbSpeed.valueProperty());

	// Create a border pane
	BorderPane pane = new BorderPane();
	pane.setCenter(ballPane);
	pane.setTop(sbSpeed);
	pane.setBottom(hBox);

	// Create a scene and place the in the stage
	Scene scene = new Scene(pane, 350, 200);
	primaryStage.setTitle("Exercise_20_05"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}