• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Auto Scroll

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic