How to configure device increment for scrollbar in JavaFX?

The ScrollBar class in JavaFX contains a property for setting the unit, which I got, but I can’t find how to get the ScrollBar on this, or set the unit increment in another way from the ScrollPane class! I suppose I should miss something obvious - how do I achieve this?

+6
source share
2 answers

Technically, you can access it using the .lookup("scrollbar") method after initializing the skin (if the scroll bar is visible). I do not like this answer.

I don't think you are missing anything according to this JIRA ticket: https://javafx-jira.kenai.com/browse/RT-16510

I would advise you to go for it, submit your use case, vote and see if you can get any answer in the future.

+4
source

you can set the ScrollEventListener to a ScrollPane and thus override the original behavior. Thus, for example, I applied ScrollPane, which scrolls horizontally, not vertically. This is what the relevant part of my code looks like:

 public class Overview extends ScrollPane { ... private void setupHorizontalScrolling() { this.setOnScroll(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent scrollEvent) { double deltaY = scrollEvent.getDeltaY()*2; // *2 to make the scrolling a bit faster double width = Overview.this.getContent().getBoundsInLocal().getWidth(); double hvalue = Overview.this.getHvalue(); Overview.this.setHvalue(hvalue + -deltaY/width); // deltaY/width to make the scrolling equally fast regardless of the actual width of the component } }); } ... } 

To satisfy your requirements, you can simply change the line in which get / setHvalue is called to get / setVvalue, and then you can configure the scroll as you want.

+6
source

Source: https://habr.com/ru/post/949605/


All Articles