Using Mouse Scroll Button In JScrollPane

Hi all.
Is it possible to use the mouse scroll button to scroll up or down in a JScrollPane, and if so, how?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JFrame implements MouseWheelListener {
  BoxListener boxListener = new BoxListener();
  JComboBox comboBox;
  JScrollPane scrollPane;
  JLabel[] labels = new JLabel[3];
  int scrollUnitIncrement = 3;
  public test() {
    String[] comboItems = {
      "3", "5", "10", "15"
    comboBox = new JComboBox(comboItems);
    comboBox.addItemListener(boxListener);
    JPanel comboBoxPanel = new JPanel();
    comboBoxPanel.add(new JLabel("scroll unit increment"));
    comboBoxPanel.add(comboBox);
    JPanel panel = new JPanel();
    panel.setPreferredSize(new Dimension(350,300));
    panel.setBackground(Color.yellow);
    panel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.fill = gbc.HORIZONTAL;
    gbc.gridwidth = gbc.REMAINDER;
    for(int j = 0; j < labels.length; j++) {
      labels[j] = new JLabel(" ", SwingConstants.CENTER);
      labels[j].setOpaque(true);
      labels[j].setBackground(Color.green);
      panel.add(labels[j], gbc);
    scrollPane = new JScrollPane(panel);
    scrollPane.addMouseWheelListener(this);
    getContentPane().add(comboBoxPanel, BorderLayout.NORTH);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(300,200);
    setLocation(300,200);
    setVisible(true);
  public void mouseWheelMoved(MouseWheelEvent e) {
    int scrollAmount;
    if(e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL)
      scrollAmount =
          e.getUnitsToScroll() * scrollUnitIncrement;
    else
      scrollAmount = e.getScrollAmount();
    labels[0].setText("Wheel rotation = " + e.getWheelRotation());
    labels[1].setText("Units to scroll = " + e.getUnitsToScroll());
    labels[2].setText("Scroll amount = " + scrollAmount);
  class BoxListener implements ItemListener {
    public void itemStateChanged(ItemEvent e) {
      String item = (String)e.getItem();
      scrollUnitIncrement = Integer.parseInt(item);
      JScrollBar verticalBar = scrollPane.getVerticalScrollBar();
      verticalBar.setUnitIncrement(scrollUnitIncrement);
  public static void main(String[] args) {
    new test();
}

Similar Messages

  • Using Mouse Scroll Button In Swing

    Hi all, here's my question:
    When using a JScrollPane, how is it possible to use the mouse scroll button found in the middle of the mouse to scroll up or down?

    Hi,
    if you are using JDK1.4 it should work. If not you would need a native implementation to catch the wheel.
    Regards
    Andre

  • Can I use mouse side buttons for pageup/pagedown like in previous version?

    In firefox 3.x I use mouse side buttons for pageup/pagedown. When I install new version I found that this buttons is used for back/forward page. Can I somehow change that?

    [[How do I customize the toolbars?]] should help you out

  • Resetting bluetooth may fix your mighty mouse scroll button

    I have had this problem with the scroll button on my mighty mouse for months and months, and the only advise I have managed to get from here when I complained was to clean it. But I tried that many times and I have had nothing but problems with it, so much so that I recently called Apple and they agreed straight away to send me a new one.
    What made me call them today was the clicking action and side buttons on my mighty mouse also failed completely, and I thought the thing was totally broke. Whilst I was on the phone I happened to mention that my wireless keyboard also keeps losing its connection, and the advisor told me to do this following...
    This advise was used on my MacBook 13.3inch model from last year.
    Turn off Mac, removed the power and battery and hold down the power button for 5 seconds. Then turn it back on, but while you turn it back on hold down the altcmnd+RP buttons together. You will hear it ching two times as it turns on, let go after the second ching.
    This apparently resets the bluetooth and it fixed my mouse, it now works perfectly.
    Anyway, I called apple back to say that this reset not only fixed my keyboard, but also my mouse. Everything now works perfectly. The problem was bluetooth all along and not that the button needed cleaning.
    But they said they would still send me out a new one, and so long as they received a mouse back in the post they wouldn't charge me. I accepted that offer and I'll see how it goes with the one I have. I feel that I may have damaged the scroll button trying to clean it and feel that I probably should get a new one anyway on account of that.

    Hello stu:
    What you apparently did (based on the feedback you got from from Apple) is reset the SMC (system management controller) and the PRAM. When one has odd problems that do not appear software related, those are sometimes suggested as troubleshooting steps.
    http://support.apple.com/kb/HT1411
    http://support.apple.com/kb/HT1379
    Resetting the SMC should not, however, be used until other avenues have been exhausted (based on Apple guidance)
    Barry
    Message was edited by: Barry Hemphill

  • Mighty Mouse scroll button

    The scroll button on my Mighty Mouse has stopped functioning. I thought it was perhaps due to a low battery level but a battery change didn't help. I've noticed the battery charge (via iStat Pro) seems to bleed quite quickly on the mouse and I've upgraded my battery choice. I like the Apple mouse pretty well... the only wireless mouse I've owned... and I've grown quite dependent on the scrolling function. Is there a history of these buttons wearing prematurely? Is there a way to "repair" a non-functioning scroll button? I'd hate to lose the mouse by attempting to disassemble something that shouldn't be tampered with. BTW, it's only about 6 months old. Thanks for input!
    jjsea

    From what I've read, Apple will replace a mouse under warranty for this reason, but to avoid the hassle of driving 50 minutes to my nearest Apple store, I just clean my mouse once per week using the damp cloth treatment. So far so good. Once per week, I run a basic maintenance program and afterwards I have to shut down and restart, so while it's shut down, I clean the mouse, the keyboard, the screen, and the case. It only takes a couple of minutes, and I keep the computer looking like new.

  • My mouse scroll button only moves up (not down)

    My scroll button on my Apple mouse (brand new iMac) was working beautifully. All of a sudden, it will not scroll down -- only up.
    Can someone give me an idea as to what might be wrong? (I checked my mouse preferences and the setting is correct, "vertical and horizontal").
    Thanks in advance.

    OK
    I have the same problem with my wireless mouse which isn't dirty, because when using it with a CAD program which uses the scroll ball as zoom in/out it works fine.
    Maybe it stopped working with the latest upgrade?.

  • Using mouse scroll wheel

    Hi,
    I've set up some buttons on my site to act as a scroll bar (here) and perform as follows...
    on(press) {
         this.onEnterFrame = function() {
              if(content._y < 95.2) {
                   content._y = content._y + 10;
    is it possible to use the scroll wheel of my mouse to do the same thing?
    I'm using Flash MX, so can only publish up to Flash player 6.
    Thanks

    Kglad
    I just coppied the syntax from above for my reply.  My actual syntax has -138.6 rather than 200.
    I've put the syntax into my action script layer on the root level.  When I trace the content._y value, it gives me it's initial position, but when I scroll it doesn't appear to do anything.
    I've not had access to a windows machine to edit my flash for a while, hence me taking so long to reply.
    I've attached what I've done.
    Thanks

  • How can I get Mighty Mouse scroll button to work?

    My Mighty Mouse has started to not respond to the scroll button. Sometimes it will scroll up but not down at all.

    If you don't mind losing warranty you mighty want to open your mouse. A good tutorial to do this can be found here: http://arstechnica.com/old/content/2005/08/dissect.ars
    I already did this twice and it worked like a charm. But be aware that you do this on your own risk.

  • Use mouse scroll wheel to change numeric control

    Does anyone know if and how I can use the mouse scroll wheel to change numeric control values?

    Another option would be to change the timeout.  This would avoid the timeout event every ms when the mouse has not "entered" the contol.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Mouse Scroll.vi ‏14 KB

  • Cannot use Mouse Scroll to Navigate Through Library Folders ?!?!?!

    Just like the title says, I cannot use my mouse scroll to navigate up and down the numerous folders I have in my library.  I can grab the page bar and move up and down (and while I'm hovering over the page bar, I can scroll up and down with the mouse wheel) - but only when I'm actually over the folders, the mouse wheel doesn't work!
    Very strange. It works fine when I'm in develop mode and I can scroll through all the presets and history.
    But when I'm in library mode, the mouse scroll doesn't move my folders up and down ?
    Anyone?

    IIRC, there is a known problem scrolling with the mouse wheel in the panels across certain "borders", i.e. into the folders section, into the collections section. You have to use the scroll bar to get across those "borders".
    See here:
    http://feedback.photoshop.com/photoshop_family/topics/lr_scrolling_over_folders_in_library _module_doesnt_work?from_gsfn=true
    Beat
    Message was edited by: b_gossweiler: added link

  • Mouse scroll button

    HI. I there a way to set the scroll button for a double- click when I press it ? I thought I had this set up on my previous system, but don't seem able to do so now.
    Thanks,
    Zach

    "I guess my only option is to set the scroll button to primary & have to click that twice ?"
    Apparently so yes. I tried double clicking my Mighty Mouse scroll and it does work and I didn't reset my preferences but one would think that would wear the scroll ball down considerably. You can't just double click the mouse itself? I switch between this and keyboard shortcuts to give my wrist a rest on occasion.
    Carolyn

  • Adobe Muse - Smooth Scrolling to Anchors Using Mouse Scroll

    I am wondering if there is a way to set up smooth scrolling to anchors with the mouse scroll in adobe muse. I can do it using links, but it would be great if the user could just start scrolling and it smoothly jumps to the next section. This looks great and would solve the issues created by variant mouse wheel speeds. Any help would be great, thanks!
    Here is an example: Layers

    There is a widget that does this quite well.  I posted it earlier, but it mist have had a mistake... or someone deleted it?  Oh well, if it disappears I wont repost it haha.
    https://creative.adobe.com/addons/products/3144#.VCCyYvldWOY

  • Can't assign "Dashboard" to Mighty Mouse Scroll Button

    For some reason assigning "Dashboard" to my Mighty Mouse middle button (Scroll) doesn't work. Any other function I assign to it works fine.
    If I assign "Dashboard" to either the left or right butons...it works fine, but I want it on the Scroll button. Any thoughts? Thanks.
    Larry

    Gave up...no replies.

  • Can't use mouse scroll within forms

    Hello,
    I have been working with SCSM 2012 since the public beta was released and I don't know why I haven't noticed this until my analysts said something but the mouse scroll wheel doesn't work within any of the forms. 
    It will scroll if you put the cursor directly over the vertical scroll bar but if the mouse is within the form its self it doesn't work.
    This is one of the most basic functionalities, is there any way to get that to work? 
    What is it about how the form is designed that doesn't allow the scrolling?
    I would be surprised if this is the first post anyone has made about this so if it's a duplicate I apologize.
    Thanks,
    Dustin

    Hi Dustin,
    I can confirm this bug, though if remember correctly, it only applies to some forms, not all. It's been reported on connect already, but please go vote on it:
    https://connect.microsoft.com/SC/feedback/details/753389/scrolling-with-mouse-wheel-in-throughout-the-system-is-inconsistent#tabs
    Regards
    //Anders
    Anders Asp | Lumagate | www.lumagate.com | Sweden | My blog: www.scsm.se

  • Use of scroll button on mouse?

    Child just got a macbook air for school's laptop program. Get ready for an endless stream of stupid questions as I try to work with Apple software and hardware. First one: I want to get her a mouse. I see in the Apple store, Apple mice with only two buttons, and a Logitech (now that is a familar name) mouse with two buttons and a middle scroll wheel.
    I'd rather not give her a mouse with a scroll bar right in the middle, that is useless. It would only serve as a distraction, whether or not the drivers can get the mouse itself to work.
    Is there any use/function in OSX for a middle scroll wheel?
    FWIW, this is for OSX 10.9.1.

    No  questions are stupid.   People ask because they don't know the answer; I'm glad you have enough confidence in Apple's forums to ask here.
    The Apple Magic mouse performs all the functions that will be required.   As for any other supplier; Logitech is well regarded here.  
    Why a centrally situated scroll wheel could be a distraction, I don't know.   Whether the scrolling is performed by a wheel or a finger gesture is quite irrelevant.   It is a necessary function.
    As you know, you need to connect it via Bluetooth.

Maybe you are looking for

  • Jasper Reports in Linux vs Jasper Reports in Windows

    Dear Sirs... an application is developed using jdeveloper 10.1.2 (struts with UIX technology) and used Jasper report to generated PDF and HTML reports programmatically (no XML files for reports tamplates are used). in jdeveloper PDF reports are gener

  • Startup Disk Error

    I'm getting startup disk almost full error and unable to import pics to Iphoto library.  What should I do?

  • Does Final Cut ProX works OK with the OS X Yosemite

    I've received a note to update my system to OS X Yosemite. Does FCPX works well with the new system? Is there any precaution that I should take before the update? Thank You for your help

  • Correlating S_ALR_87013537 tcode to underlying report

    How can I correlate the S_ALR_87013537 tcode to underlying report? I would like to change the settings on the report (using tcode cje2) , but I do not know which report is associated with  the S_ALR_87013537 tcode. I'm trying to change the "Output Ty

  • Dynamic IF statement...like dynamic where clause...

    Hi, I know how to do a dynamic where clause by putting (varname) like shown below - select * from cust_mstr where (varname). Can I do it something like this in IF statement. if (varname). endif. The varname will have different conditions. Your help w