Oundroni Asked: 2020-02-09 09:09:34 +0800 CST 2020-02-09 09:09:34 +0800 CST 2020-02-09 09:09:34 +0800 CST Vertical scroll bar to the left of a ScrollPane in JavaFX 772 Using Java FXIs it possible to place the vertical scroll bar from one scrollPaneto the left? javafx 2 Answers Voted Jorgesys 2020-02-09T09:35:19+08:002020-02-09T09:35:19+08:00 Unfortunately not, in a Scroll Pane, you can only manipulate properties of the Horizontal bars whose position is down and Vertical right position, which are the only ones implemented for this control. Best Answer Oundroni 2020-04-06T23:38:32+08:002020-04-06T23:38:32+08:00 A possible solution is: Create aScrollBar Associate through bindthe ScrollBarwith theScrollPane Hide the vertical scroll barScrollPane Here is a small working example: import javafx.application.Application; import javafx.geometry.Orientation; import javafx.scene.Scene; import javafx.scene.control.ScrollBar; import javafx.scene.control.ScrollPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import javafx.scene.shape.Line; import javafx.stage.Stage; public class ScrollbarIzquierda extends Application { @Override public void start(Stage stage) { Pane pane = new Pane(); Line line = new Line(100, 100, 1000, 1000); pane.getChildren().add(line); ScrollPane scrollPane = new ScrollPane(); scrollPane.setContent(pane); ScrollBar vScrollBar = new ScrollBar(); vScrollBar.setOrientation(Orientation.VERTICAL); vScrollBar.minProperty().bind(scrollPane.vminProperty()); vScrollBar.maxProperty().bind(scrollPane.vmaxProperty()); vScrollBar.visibleAmountProperty().bind(scrollPane.heightProperty().divide(pane.heightProperty())); scrollPane.vvalueProperty().bindBidirectional(vScrollBar.valueProperty()); ScrollBar hScrollBar = new ScrollBar(); hScrollBar.setOrientation(Orientation.HORIZONTAL); hScrollBar.minProperty().bind(scrollPane.hminProperty()); hScrollBar.maxProperty().bind(scrollPane.hmaxProperty()); hScrollBar.visibleAmountProperty().bind(scrollPane.widthProperty().divide(pane.heightProperty())); scrollPane.hvalueProperty().bindBidirectional(hScrollBar.valueProperty()); scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); HBox hBox = new HBox(); HBox.setHgrow(scrollPane, Priority.ALWAYS); hBox.getChildren().addAll(vScrollBar, scrollPane); VBox vBox = new VBox(); VBox.setVgrow(hBox, Priority.ALWAYS); vBox.getChildren().addAll(hScrollBar, hBox); Scene scene = new Scene(vBox, 500, 400); scene.getStylesheets().add(this.getClass().getResource("style.css").toExternalForm()); stage.setScene(scene); stage.show(); vScrollBar.requestLayout(); hScrollBar.requestLayout(); } public static void main(String[] args) { launch(args); } } And the CSS: .scroll-pane { -fx-background-insets: 0; -fx-padding: 0; } .scroll-pane:focused { -fx-background-insets: 0; } .scroll-pane .corner { -fx-background-insets: 0; }
Unfortunately not, in a
Scroll Pane
, you can only manipulate properties of the Horizontal bars whose position is down and Vertical right position, which are the only ones implemented for this control.A possible solution is:
ScrollBar
bind
theScrollBar
with theScrollPane
ScrollPane
Here is a small working example:
And the CSS: