I have a SplitPane
in my main GUI that is behaving strangely. I am trying to save the position between executions of the program and do so by writing/reading a simple text file.
However, I am noticing that the getPosition()
method returns an incorrect value when saving it to the file.
When exiting the program, I am saving the position with this code:
Settings.setSplitPaneLocation(Global.commentMasterController.getSplitPane().getDividers().get(0).getPosition());
Global
is a Singleton that holds references to my main GUI controllers.Settings
is another Singleton that contains the values loaded from the settings file.
Upon loading the program, I set the position of the SplitPane
by loading the last saved value from the Settings
class:
splitPane.setDividerPosition(0, Settings.getSplitPaneLocation());
The problem is, when I load the program, even if I don't adjust the SplitPane
position at all (load the program and immediately exit), the position that is saved is different from the position it was initially set to.
Here is the output, showing 3 consecutive runs of the program. Again, this is just running the program and immediately exiting; I don't adjust the position of any controls at all:
setDividerPosition(): 0.9247730220492867
getDividerPosition(): 0.9105058365758755
setDividerPosition(): 0.9105058365758755
getDividerPosition(): 0.893644617380026
setDividerPosition(): 0.893644617380026
getDividerPosition(): 0.874189364461738
As you can see, getDividerPosition()
returns a different value than the actual position of the divider.
I have checked the max/min sizes of the child nodes within the SplitPane
and the min size is set to 0.