🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1603

Re: Jscrollbar events

#1603
From: Tad Frysinger [TeamB]
Date: Wed, 22 Oct 2003 15:49
50 lines
2981 bytes
Zoran Pjevic wrote:
> I just can't find out what events are fired when the buttons of a
> Jscrollbar are pressed?
> 
> MousePresse fires events if the knob of the scrollbar is pressed, but
> I need the events for the scrollbar buttons.
> 
> Thanks for any advice,
> Zoran
> 
JScrollBar fires AdjustmentEvent events when the minimum, maximum, value 
and visible amount properties (i.e. the model properties) are changed. 
You can look at the valueIsAdjusting property to see if the scroller is 
being scrolled or not. Since these values change when the mouse is 
clicked, you can determine when the mouse was clicked, and since the 
amounts change either going down (up button was clicked) or up (down 
button was clicked), you can determihe WHICH mouse was clicked.

Try something like (not optimized):

     jScrollPane1.getVerticalScrollBar().addAdjustmentListener(new 
AdjustmentListener() {
       int adjustedValue = jScrollPane1.getVerticalScrollBar().getValue();
       boolean adjustingByThumb = false;
       public void adjustmentValueChanged( AdjustmentEvent adj ) {
         JScrollBar bar = ((JScrollBar)adj.getAdjustable());
         if ( bar.getValueIsAdjusting() ) {
           adjustingByThumb = true;
         } else {
           int adjValue = adj.getValue();
           if ( !adjustingByThumb ) {
             if (adjustedValue > adjValue) {
               System.out.println("Top button clicked");
             }
             else if (adjustedValue < adjValue) {
               System.out.println("Bottom button clicked");
             }
           }
           adjustingByThumb = false;
           adjustedValue = adjValue;
         }
       }
     });

Note that this will only get you events if the value actually changes. 
If you just want to know if the user clicks on the up arrow when the 
thumb is already at the top, this won't help.

-- 
Tad Frysinger [TeamB]
Technical Details
Message-ID: <3f96a6fd$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <epqsovgkqeusuvo04palvckao7kr9b6dfj@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,eef0f40fd021456f
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2003-10-22 09:12:39 PST
Date: Wed, 22 Oct 2003 09:49:01 -0600
From: "Tad Frysinger [TeamB]" <tfrysinger@earthlink.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: Jscrollbar events
References: <epqsovgkqeusuvo04palvckao7kr9b6dfj@4ax.com>
In-Reply-To: <epqsovgkqeusuvo04palvckao7kr9b6dfj@4ax.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 206.61.185.113
Message-ID: <3f96a6fd$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1066837757 206.61.185.113 (22 Oct 2003 08:49:17 -0700)
Lines: 51
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail