As you can see, I'm trying to figure out what to put on this line:
Don't put anything. You should not be attempting to manage the size of the frame. For example, your code doesn't even consider the Borders of the frame. If anything your code would be changed to use the width of the frame, not the scrollpane.
The better solution is to override the getPreferredSize()
method of the scroll pane to return the width of super.getPreferredSize()
and then specify a reasonable height. You would need to make sure the vertical scrollbar is always visible for the calculation to work.
Then the pack() method will work as expected.