I'm not really sure what an NScrollPane
is, or what the component returned from getNpQuestionArea()
is, but it looks like they're probably just an extension of JComponent
s. In that case, you can probably call the following...
getNpQuestionArea().scrollRectToVisible(new Rectangle(0,0,0,0));
Also, assuming that NScrollPane
is an extension of JScrollPane
, if you pass in the getNpQuestionArea()
into the constructor of the NScrollPane
, I believe it should automatically be at the top. So, something like this...
nspQuestionArea = new NScrollPane(getNpQuestionArea());
If you parse the JComponent
into the NScrollPane
constructor, I believe it positions the scrollbar at the top-left of the JComponent
. However, if you add the JComponent
later by calling setViewportView()
, it positions it centrally by default. It has something to do with the way that the JComponent
s are layed-out when generating the display - if you add it in the constructor, it lays out the NScrollPane
to the correct size and location for the JComponent
that you pass to it. However, if you create a default NScrollPane
and only give it the JComponent
later, it just creates a NScrollPane
at a default size, rather than fitting it appropriately to the JComponent
.
Give both of these a try and see how you go.