turtletimer
asked on
JViewport programatically scrolling
I created my own scroll pane by extending JViewport. This is a chat window, so it's size is dynamic. Everything works great except it won't stay scrolled to the bottom, it is always on the very top. When someone types I want it to scroll so you can see what was typed. I have a JTextPane within the viewport. I use the setCaret method to position the caret to the bottom the the textpane. I also do this.
public void autoScroll(){
if(this.getView().getHeigh t()>this.g etHeight() ){
int max = getMaxYExtent();
Point mpt = new Point(pt.x, max);
this.setViewPosition(mpt);
}
private int getMaxYExtent(){
return this.getView().getSize().h eight-this .getSize() .height;
}
This does work. I can see it scroll but something resets it back. I tried debuggin and checking what happened after this and it just goes to a bunch of my paint methods. What resets the viewport to the top?
public void autoScroll(){
if(this.getView().getHeigh
int max = getMaxYExtent();
Point mpt = new Point(pt.x, max);
this.setViewPosition(mpt);
}
private int getMaxYExtent(){
return this.getView().getSize().h
}
This does work. I can see it scroll but something resets it back. I tried debuggin and checking what happened after this and it just goes to a bunch of my paint methods. What resets the viewport to the top?
ASKER
I wanted custum scroll buttons and no thumb or track.....i thought this would be the easiest way as opposed to messing with the UI. Everything works great except it doesn't stay scrolled like a JScrollPane.
I don't understand your other question.
I don't understand your other question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And what component is help in your viewport?