• Post Reply Bookmark Topic Watch Topic
  • New Topic

JScrollBar issue  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I require my JScrollBar to trigger a repaint, when the mouse is released from the bar.
I managed to solve this by adding a MouseListener to the JScrollBar object, and just implementing the mouseReleased method.

But the problem is that when the 2 ends of the JScrollBar(the unit increment/decrement things) are released, it does not recognise this as a mouse release, and mouseReleased(...) is never invoked.

I tried to remove the 2 end things, to just leave the bar, but I couldn't seem to do this, is there any other way to solve this problem?

Thanks for any help.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rather than a mouselistener, would things work better using a ChangeListener? You'd probably have to add it to the model. Something like so:


[ October 12, 2008: Message edited by: pete stein ]
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much, nice bit of code..

It does work, but theres a slight glitch,

Basically when mouse is held on the scrollbar, or its end things.. I need it to trigger a certain repaint (say repaint1),
But when mouse is released from scrollbar, or its end things.. I need it to trigger a different repaint (say repaint2).

I tried using your code as well as having an AdjustmentListener on my scrollbar (implementing adjustmentValueChanged(AdjustmentEvent ae)),
but it doesnt work well.
After moving scrollbar, then releasing it, repaint1 and repaint2 are both called, where I just require repaint2.
And when mouse is held over the 2 end things of scrollbar, both repaint1 and repaint2 are invoked..
( repaint1,repaint2,repaint1,repaint2,repaint1,repaint2,...)
When I just require repaint1, while mouse is held on it, and repaint2, when it is released.

Thanks for any help.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I created was kind of an SSCCE to illustrate my solution to your problem. If you have more issues to solve, I suggest that you create your own SSCCE and post it here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!