Search code examples
javajavafxdynamicwindow

JavaFX - Change ScrollPane's vvalue to a specific amount based on Window size


I have an application which has a side bar, and one of the items in the sidebar is a Settings option. This option in the side bar has many sub-items, these items being the different headers on the Settings page. This page which contains every Settings item, and I am looking for a way to set the ScrollPane's vvalue of this window based on which sub-item was selected so that the item they selected will be at the very top of the screen.

I have been successful with hard coding the vvalue, of course, but once the size of the window changes it is no longer scrolled down to the exact point in which I want it to be. Below you can see an image of my application on the Settings page. Based on the image, if the user would select the Setting2 option in the sub menu, I would want the ScrollPane's vvalue to change where the Setting2 header was at the very top of the screen no matter what the size of the application window is.

enter image description here


Solution

  • Following @jewelsea 's approach I was able to fix my problem, thanks!

    His answer was:

    Could you put the Settings objects on the right into a ListView and use scrollTo(object) to scroll to the appropriate setting?