Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JScrollPane positioning and Vertical ScrollBar

Status
Not open for further replies.

pisth

Programmer
Mar 18, 2003
43
US
Hi,
I have attached a JScrollPane to a text area.
the code is as follows.

JScrollPane jsp = new JScrollPane( jtx1 );

however since the contents in the JTextArea is large horinontally, the text gets displayed in the textarea. However the scroller in the JScrollPane gets positioned towards the end of the text. How do I specify to make sure that the Scroller is always in the start of the text?

and also i wanted the Vertical ScrollBar to be always visble and what i did was:

int vpolicy = jsp.getVerticalScrollBarPolicy();
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

The Vertical ScrollBar gets displayed. However I am not ablt to see the scroller in the JScrollPane's vertical bar as I don't have sufficient text vertically. How do i specify that the scroller always be present in my vertical side...irrespective of the contents in the Textarea. i.e i always want to scroll. (I see the ScrollBAr. however am not able to scroll b'coz i have less text.)

Thanks!

Regards,
Karthik.
 
The vertical scrolling can't be infinite - the component needs an end to the scrolling range so it can calculate where on the scroll bar the slider should be. As you discovered, it uses the end of your text to do that calculation.

You can just append as many line feeds to the end of your text as you need to ensure you can always scroll down the desired amount.
 
My question was: how do i position my scroller in Horizontal Bar of JScrollPane to the start of text?
 
You could create a JScrollBar object, set its properties and then add it to the JScrollPane using:

Code:
 JScrollPane.setHorizontalScrollBar(<name of object>);

?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top