can`t set a JScrollBar position correctly

jTextArea1 =new JTextArea(){

publicvoid append(String text){

super.append(text);

JScrollPane scrollPane = (JScrollPane) ((JViewport)getParent()).getParent();

int max = scrollPane.getVerticalScrollBar().getMaximum();

int vis = scrollPane.getVerticalScrollBar().getVisibleAmount();

scrollPane.getVerticalScrollBar().setValue(max - vis);

System.out.println("max = " + max);

System.out.println("vis = " + vis);

System.out.println("val = " + (max - vis) +" = " + scrollPane.getVerticalScrollBar().getValue());

}

};

the output prints always a diferent value for max - vis and the scrollbar getValue(), even I setted it just before ( setValue(max - vis) ). Shouldn`t max - vis be the maximum value of the bar, so it would be at bottom ?

[1180 byte] By [SrLontraa] at [2007-11-27 1:46:13]
# 1
To position the scrollbar at the bottom after you append text you can use:textArea.setCaretPosition( textArea.getDocument().getLength() );
camickra at 2007-7-12 1:07:30 > top of Java-index,Desktop,Core GUI APIs...