Hi,
I've found a few posts on this topic, but I cannot seem to figure out how to apply them to my situation. I have a JScrollPane and whenever the text in it exceeds the size of the box the vertical scroll bar appears as expected; however, the pane's default position is always at the bottom of the text. I would like to have the position default to the top of the pane - simple enough right?
Here is the code for the pane:
// Overview
JLabel overviewLbl = ActionLabel.getOverviewLabel();
topGbc.gridx = 0;
topGbc.gridy = line_count++;
topGbc.insets = new Insets(0,0,0,0);
topGbc.anchor = GridBagConstraints.WEST;
topGbc.gridwidth = 4;
topGbc.gridheight = 1;
topGb.setConstraints( overviewLbl, topGbc );
super.getContentPane().add( overviewLbl );
overviewTA = new PLTextArea();
overviewTA.setEditable( false );
PLScrollPane overviewSP = new PLScrollPane( overviewTA );
overviewSP.setPreferredSize( new Dimension( 470, 80 ));
overviewSP.setVerticalScrollBarPolicy( PLScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
overviewSP.getViewport().setViewPosition(new Point(0,0));
topGbc.gridx = 0;
topGbc.gridy = line_count++;
topGbc.insets = new Insets( 0,PLDefault.LEFT_INSET,0,0 );
topGbc.anchor = GridBagConstraints.WEST;
topGbc.gridwidth = 4;
topGb.setConstraints( overviewSP, topGbc );
super.getContentPane().add( overviewSP );
in the code above I have inserted the line
overviewSP.getViewport().setViewPosition(new Point(0,0));
to try to set the default position to the top, and it is not working. I've also tried this line
overviewSP.getVerticalScrollbar().setValue(0);
but it didn't work either.
Here is the code for the PLScrollPane constructor:
public class PLScrollPane extends JScrollPane{
public PLScrollPane(Component arg0) {
super(arg0);
super.setBackground(PLColor.BACKGROUND);
getViewport().setBackground(PLColor.SCROLLPANE_BACKGROUND);
getHorizontalScrollBar().setBackground(PLColor.SCROLLBAR_BACKGROUND);
getHorizontalScrollBar().setForeground(PLColor.SCROLLBAR_FOREGROUND);
getVerticalScrollBar().setBackground(PLColor.SCROLLBAR_BACKGROUND);
getVerticalScrollBar().setForeground(PLColor.SCROLLBAR_FOREGROUND);
setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
}
}
I also tried putting both lines I mentioned above in this constructor, which did not work either. If anyone could point me in the right direction here I'd appreciate it. This seems like it's probably a dumb mistake I'm making, but I cannot figure this one out! Thanks...