I have created a solution that should meet your requirements, although I cannot guarantee its compatibility with future JavaFX versions.
To achieve this, I analyzed the default modena style sheet and removed all padding and insets associated with the scroll bar buttons to make them invisible. Then, I set a preferred size for the scroll bars based on this modification.
While there may be more efficient ways to handle this and hide elements, my approach seemed to work effectively. It is possible that fewer rules could be used as well, but for now, this solution sufficed.
It's important to note that if you minimize the scroll pane too much, the default behavior is to hide the thumb and allow movement only via the buttons, which are no longer visible in your case. Therefore, avoid reducing the scroll pane size excessively to maintain panning capabilities within the scroll pane.
Here is an example code snippet:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class NoButtonScroll extends Application {
private static final Lorem lorem = new Lorem();
// Styling for removing scroll bar buttons
private static final String NO_BUTTON_SCROLL_BARS = """
/* CSS styling goes here */
""";
@Override public void start(Stage stage) {
ScrollPane standardScrollPane = new ScrollPane(generateText());
ScrollPane noButtonScrollPane = new ScrollPane(generateText());
noButtonScrollPane.getStylesheets().add(NO_BUTTON_SCROLL_BARS);
final VBox layout = new VBox(10, standardScrollPane, noButtonScrollPane);
layout.setPadding(new Insets(10));
layout.setPrefSize(600, 400);
stage.setScene(new Scene(layout));
stage.show();
}
private Text generateText() {
Text sampleText = new Text(lorem.nextText(500));
sampleText.setWrappingWidth(800);
return sampleText;
}
// Class for generating example text for test data
private static final class Lorem {
private static final String[] lorem = "lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua".split(" ");
private int idx = 0;
public String nextWord() {
return lorem[getAndIncrementIdx()];
}
public String nextText(int nWords) {
return IntStream.range(0, nWords)
.mapToObj(i -> nextWord())
.collect(Collectors.joining(" "));
}
private int getAndIncrementIdx() {
int retVal = idx;
idx = (idx + 1) % lorem.length;
return retVal;
}
}
public static void main(String[] args) { launch(args); }
}