Re: Custom JScrollPane - Double JScrollBars
"pek" <kimwlias@gmail.com> wrote in message
news:93b20fb7-45eb-46c6-81af-340af16dd965@24g2000hsh.googlegroups.com...
On Apr 29, 5:07 pm, "David A. Redick" <tinyweldingto...@gmail.com>
By the way, there is a little problem. I'm running Linux, and when the
knob is being dragged, it moves the view perfectly. But if let's say,
I drag the knob from the middle to 1/3 position and just hold the knob
there, the view doesn't move. As long as the knob is being dragged it
does. I hope you understand what I'm saying.
Something like this should work:
private Timer horizTimer = new Timer(250,
new ActionListener() {
public void actionPerformed(ActionEvent ev) {
int iDir = m_pHSB2.getDir();
int iInc = horizontalScrollBar.getUnitIncrement(iDir);
int iSpeed = m_pHSB2.getSpeed();
iInc *= iSpeed;
int iValue = horizontalScrollBar.getValue();
iValue += iDir*iInc;
horizontalScrollBar.setValue(iValue);
}
});
private Timer vertTimer = new Timer(250,
new ActionListener() {
public void actionPerformed(ActionEvent ev) {
int iDir = m_pVSB2.getDir();
int iInc = verticalScrollBar.getUnitIncrement(iDir);
int iSpeed = m_pVSB2.getSpeed();
iInc *= iSpeed;
int iValue = verticalScrollBar.getValue();
iValue += iDir*iInc;
verticalScrollBar.setValue(iValue);
}
});
public void adjustmentValueChanged(final AdjustmentEvent e)
{
SpringyScrollBar p = (SpringyScrollBar) e.getAdjustable();
boolean bIsHoriz = p.equals(m_pHSB2);
Timer timer = bIsHoriz? horizTimer : vertTimer;
if(!e.getValueIsAdjusting())
{
// move back to center
timer.stop();
p.moveToMid();
}
else {
if (p.getSpeed() != 0 && !timer.isRunning()) {
timer.start();
}
}
}