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

  • Home
  • SEARCH
  • 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 9110297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:14:11+00:00 2026-06-17T03:14:11+00:00

I have a JScrollpane which contains a big JPanel and the JPanel it’s self

  • 0

I have a JScrollpane which contains a big JPanel and the JPanel it’s self contains 3 JPanels. each of those 3 JPanels has the same size as the JScrollpane. the user can not scroll. he can clicks on a button and sees the next or previous JPanel (only 1 panel can bee seen at a moment and he can not see a part of one panel and part of other…).

How can I understand which panel is being seen right now?

  • 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-17T03:14:13+00:00Added an answer on June 17, 2026 at 3:14 am

    Assuming the setup as outlined in my comment to your question, the basic approach is to compare the parent’s (the component that contains the 3 panels) visibleRect with its children’s bounds. Something like:

    final JComponent parent = new JPanel(); // new PageScrollable();
    parent.setLayout(new BoxLayout(parent, BoxLayout.PAGE_AXIS));
    Color[] color = new Color[] {Color.YELLOW, Color.RED, Color.GREEN}; 
    for (int i = 0; i < color.length; i++) {
        JTable table = new JTable(10, 5);
        // color it to see some difference
        table.setBackground(color[i]);
        // set a name for logging
        table.setName("table at: " + i);
        parent.add(table);
    }
    
    JScrollPane scrollPane = new JScrollPane(parent);
    Action visible = new AbstractAction() {
    
        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle rect = parent.getVisibleRect();
            for (int i = 0; i < parent.getComponentCount(); i++) {
                // implement logic as needed to compare the parent's visible rect
                // with the children's bounds
                if (rect.intersects(parent.getComponent(i).getBounds())) {
                    System.out.println("found: " + parent.getComponent(i).getName());
                }
            }
        }
    
    };
    frame.add(scrollPane); 
    frame.add(new JButton(visible), BorderLayout.SOUTH);
    

    As an aside: to fine-tune scrolling behaviour you might consider a custom panel which implements Scrollable, something like:

    /**
     * Implement a panel of type Scrollable to fine-tune its scrolling behaviour.
     * This implements the prefScrollableSize to the prefSize of the first child
     * and both block/unit increment to the height of the prefScrollable.
     */
    public static class PageScrollable extends JPanel implements Scrollable {
    
        @Override
        public Dimension getPreferredScrollableViewportSize() {
            if (getComponentCount() > 0) {
                return getComponent(0).getPreferredSize();
            }
            return super.getPreferredSize();
        }
    
        @Override
        public int getScrollableUnitIncrement(Rectangle visibleRect,
                int orientation, int direction) {
            return getPreferredScrollableViewportSize().height;
        }
    
        @Override
        public int getScrollableBlockIncrement(Rectangle visibleRect,
                int orientation, int direction) {
            return getPreferredScrollableViewportSize().height;
        }
    
        @Override
        public boolean getScrollableTracksViewportWidth() {
            return false;
        }
    
        @Override
        public boolean getScrollableTracksViewportHeight() {
            return false;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JScrollpane which contains a scrollable client that changes its size dynamically
I have a JScrollPane , which has a JPanel for its content pane. To
I have Java application which adds JTextFields @ runtime to JPanel. Basically user clicks
I have JScrollPane which contains only one instance of JTree. How can I set
So, I have a grid layout which stores JScrollPane's in each cell. These are
I have the following class which implements 3 JPanels. 1 Panel has a label,
I have a JPanel which I'm placing inside of a JScrollPane . I am
I have a JFrame which contains a JPanel . The frame can be resized
I have created a JPanel which contains an arbitrary number of JLabels, laid out
I have a JPanel panel which contains a JTree tree . Sometimes the JTree

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.