Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:54:00+00:00 2026-06-07T16:54:00+00:00

I have a JScrollPane whose content pane is a JXList. When I use the

  • 0

I have a JScrollPane whose content pane is a JXList. When I use the mouse wheel on the list, the list steps three (3) items at a time. This also works for a table, regardless of row height. How can I change this so that – regardless of platform – for both list and table the scroll distance is exactly 1 item? Setting block increment doesn’t cut it because some rows in the table have a different height.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:54:01+00:00Added an answer on June 7, 2026 at 4:54 pm

    Out of pure interest (and a little boredom) I created a working example:

    /**
     * Scrolls exactly one Item a time. Works for JTable and JList.
     *
     * @author Lukas Knuth
     * @version 1.0
     */
    public class Main {
    
        private JTable table;
        private JList list;
        private JFrame frame;
    
        private final String[] data;
    
        /**
         * This is where the magic with the "just one item per scroll" happens!
         */
        private final AdjustmentListener singleItemScroll = new AdjustmentListener() {
            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                // The user scrolled the List (using the bar, mouse wheel or something else):
                if (e.getAdjustmentType() == AdjustmentEvent.TRACK){
                    // Jump to the next "block" (which is a row".
                    e.getAdjustable().setBlockIncrement(1);
                }
            }
        };
    
        public Main(){
            // Place some random data:
            Random rnd = new Random();
            data = new String[120];
            for (int i = 0; i < data.length; i++)
                data[i] = "Set "+i+" for: "+rnd.nextInt();
            for (int i = 0; i < data.length; i+=10)
                data[i] = "<html>"+data[i]+"<br>Spacer!</html>";
            // Create the GUI:
            setupGui();
            // Show:
            frame.pack();
            frame.setVisible(true);
        }
    
        private void setupGui(){
            frame = new JFrame("Single Scroll in Swing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            frame.add(split);
    
            // Add Data to the table:
            table = new JTable(new AbstractTableModel() {
                @Override
                public int getRowCount() {
                    return data.length;
                }
    
                @Override
                public int getColumnCount() {
                    return 1;
                }
    
                @Override
                public Object getValueAt(int rowIndex, int columnIndex) {
                    return data[rowIndex];
                }
            });
            for (int i = 0; i < data.length; i+=10)
                table.setRowHeight(i, 30);
            JScrollPane scroll = new JScrollPane(table);
            // Add out custom AdjustmentListener to jump only one row per scroll:
            scroll.getVerticalScrollBar().addAdjustmentListener(singleItemScroll);
            split.add(scroll);
    
            list = new JList<String>(data);
            scroll = new JScrollPane(list);
            // Add out custom AdjustmentListener to jump only one row per scroll:
            scroll.getVerticalScrollBar().addAdjustmentListener(singleItemScroll);
            split.add(scroll);
        }
    
        public static void main(String[] agrs){
            new Main();
        }
    }
    

    The real magic is done in the custom AdjustmentListener, where we go and increase the current “scroll-position” by one single block per time. This works up and down and with different row-sizes, as shown in the example.


    As @kleopatra mentioned in the comments, you can also use a MouseWheelListener to only redefine the behavior of the mouse-wheel.

    See the official tutorial here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been unsuccessful getting the mouse wheel to scroll a horizontal jscrollpane. Does
I have a JScrollPane , which has a JPanel for its content pane. To
I have a situation like this. I have scrollpane whose viewportView is a JPanel
I have scrollbars using the jScrollPane plug-in for jQuery. The scrollbar works, all content
I have this piece of code for a jScrollPane that changes the top arrow's
I have used the scroll bar which is extracted from this site http://jscrollpane.kelvinluck.com/arrow_hover.html .
I have a jScrollpane (jQuery) problem I use jScrollpane on my website. I have
I have been trying to use JScrollPane with my applet, but it doesn't work.
I have a JScrollPane containing a JPanel. I fill this JPanel with many buttons.
I have this JTextPane (wrapped in a JScrollPane ) that is backed by a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.