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 8212143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:39:52+00:00 2026-06-07T10:39:52+00:00

I have a JTable inside a JPanel . I can scroll up and down

  • 0

I have a JTable inside a JPanel. I can scroll up and down the JPanel using the mouse’s scroll wheel, but when my mouse is hovering over the JTable, I have to move it out of the table to scroll back up the JPanel using the scroll wheel. Is there a way I can scroll up and down the JPanel using the scroll wheel if the mouse is hovering over the JTable?

  • 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-07T10:39:54+00:00Added an answer on June 7, 2026 at 10:39 am

    I took Xeon’s advice in the comment above and implemented a mouse wheel listener that forwards mouse wheel events to the parent component. See the code below.

    public class CustomMouseWheelListener implements MouseWheelListener {
    
      private JScrollBar bar;
      private int previousValue = 0;
      private JScrollPane parentScrollPane;
      private JScrollPane customScrollPane;
    
      /** @return The parent scroll pane, or null if there is no parent. */
      private JScrollPane getParentScrollPane() {
        if (this.parentScrollPane == null) {
          Component parent = this.customScrollPane.getParent();
          while (!(parent instanceof JScrollPane) && parent != null) {
            parent = parent.getParent();
          }
          this.parentScrollPane = (JScrollPane) parent;
        }
        return this.parentScrollPane;
      }
    
      /**
       * Creates a new CustomMouseWheelListener.
       * @param customScrollPane The scroll pane to which this listener belongs.
       */
      public CustomMouseWheelListener(JScrollPane customScrollPane) {
        ValidationUtils.checkNull(customScrollPane);
        this.customScrollPane = customScrollPane;
        this.bar = this.customScrollPane.getVerticalScrollBar();
      }
    
      /** {@inheritDoc} */
      @Override
      public void mouseWheelMoved(MouseWheelEvent event) {
        JScrollPane parent = getParentScrollPane();
        if (parent != null) {
          if (event.getWheelRotation() < 0) {
            if (this.bar.getValue() == 0 && this.previousValue == 0) {
              parent.dispatchEvent(cloneEvent(event));
            }
          }
          else {
            if (this.bar.getValue() == getMax() && this.previousValue == getMax()) {
              parent.dispatchEvent(cloneEvent(event));
            }
          }
          this.previousValue = this.bar.getValue();
        }
        else {
          this.customScrollPane.removeMouseWheelListener(this);
        }
      }
    
      /** @return The maximum value of the scrollbar. */
      private int getMax() {
        return this.bar.getMaximum() - this.bar.getVisibleAmount();
      }
    
      /**
       * Copies the given MouseWheelEvent.
       * 
       * @param event The MouseWheelEvent to copy.
       * @return A copy of the mouse wheel event.
       */
      private MouseWheelEvent cloneEvent(MouseWheelEvent event) {
        return new MouseWheelEvent(getParentScrollPane(), event.getID(), event.getWhen(),
            event.getModifiers(), 1, 1, event.getClickCount(), false, event.getScrollType(),
            event.getScrollAmount(), event.getWheelRotation());
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable inside a JScrollPane; How can I get the JTable? Thanks
I have a JTable that holds several JPanels using a custom renderer/editor. The JPanel
I have a JPanel that contains a JScrollPane that contains a JTable. Inside my
I have a JTable inside of a JScrollPane . I am creating a custom
I have a JTable inside a JScrollPane. After calling my function which should populate
I have a JTable inside a JScrollPane. In one of the columns in the
I have a JTable called Cart where user can add products before buying them.
I have a JTable and, inside its TableModel, I saved an int; this is
I have a standard JTable with certain data inside. I would like to create
I have a JTable that is using a TableColumnModelListener() to detect when the column

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.