Java Swing Question JScrollBar

AFB

Lifer
Jan 10, 2004
10,718
3
0
I have a JText area that I want to scroll down as far as possible when I add text if the user has it scrolled down before the text was added.


So far, I have:


boolean needToScroll = false;
JScrollBar vb = scrollPane.getVerticalScrollBar() ;
vb.setMaximum(100);
System.out.println("Maximum : " +vb.getMaximum() + " Current : " + vb.getValue() );
if(vb.getValue() == vb.getMaximum())
{
needToScroll = true;
}


My problem is that is that getValue() returns a number that is always smaller than getMaximum() even when it's scrolled all the way to the bottom.



Any ideas? :confused:




Thanks :beer: :thumbsup::D
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
the deswcription of setMaximum() says this:

Sets the model's maximum property. Note that the scrollbar's value can only be set to maximum - extent.

you can use getVisibleAmount() to get the extent
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: dighn
the deswcription of setMaximum() says this:

Sets the model's maximum property. Note that the scrollbar's value can only be set to maximum - extent.

you can use getVisibleAmount() to get the extent

Thatnks :):D :beer: