• Post Reply Bookmark Topic Watch Topic
  • New Topic

Auto Scroll  RSS feed

 
Tys Seyffert
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
How can I force the scrollpane to scroll when the user tabs out of the screen?
 
Tys Seyffert
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys
i came right
here is the method i used
//panel1 = panel
//scroll = scrollpane
JComponent c = (JComponent)source;
if ( ! c.isShowing())
return;

int ipanel1Y = panel1.getLocationOnScreen().y;
int iComponentY = c.getLocationOnScreen().y;
int iComponentTop = iComponentY - ipanel1Y;
int iTarget = iComponentTop - SCROLLTO_FROMTOP;

int iscrollY = scroll.getLocationOnScreen().y;
int iscrollTop = iscrollY - ipanel1Y;
int iscrollBottom = iscrollTop + scroll.getSize().height;

intiScrollMargin = 100;

JScrollBar bar = scroll.getVerticalScrollBar();

if (iComponentTop < (iscrollTop + iScrollMargin) ||
iComponentTop > (iscrollBottom - iScrollMargin)
)
{
int iCurY = bar.getValue();
int iDiff = iCurY - iTarget;

if (iDiff > 500 || iDiff < -500){
bar.setValue(iCurY);
}
else
{
while (iCurY != iTarget)
{
if (iCurY < iTarget){
iCurY += SCROLL_INCREMENT;
}
else{
iCurY -= SCROLL_INCREMENT;
}

if ( (iCurY - iTarget > 0 && iCurY - iTarget < SCROLL_INCREMENT) ||
(iCurY - iTarget < 0 && iTarget - iCurY < SCROLL_INCREMENT)){
iCurY = iTarget;
}
bar.setValue(iCurY);
}
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!