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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:05:41+00:00 2026-06-03T02:05:41+00:00

I have JScrollPane that contains some images in a horizontal row. If the row

  • 0

I have JScrollPane that contains some images in a horizontal row. If the row of images is too long for the view port, the JScrollPane shows a scroll bar, reducing the height of the view port. I’d like to resize the images to fit the view port. How can I detect that the view port changed its size? Unfortunately, registering change event handlers doesn’t seem to work.

  • 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-03T02:05:43+00:00Added an answer on June 3, 2026 at 2:05 am

    Using change listener on the ViewPort seems to work for me. Here is a small demo of that:

    import java.awt.BorderLayout;
    import java.io.UnsupportedEncodingException;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.SwingWorker;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    
    public class Main {
    
        public static void main(String[] args) throws UnsupportedEncodingException {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel panel = new JPanel(new BorderLayout());
            final JPanel buttons = new JPanel();
            final JScrollPane pane = new JScrollPane(buttons);
            pane.getViewport().addChangeListener(new ChangeListener() {
    
                @Override
                public void stateChanged(ChangeEvent e) {
                    System.err.println("Change in " + e.getSource());
                    System.err.println("Vertical visible? " + pane.getVerticalScrollBar().isVisible());
                    System.err.println("Horizontal visible? " + pane.getHorizontalScrollBar().isVisible());
                }
            });
            panel.add(pane);
            frame.setContentPane(panel);
            frame.setSize(300, 200);
            frame.setVisible(true);
            SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
    
                @Override
                protected Void doInBackground() throws Exception {
                    for (int i = 0; i < 10; i++) {
                        Thread.sleep(800);
                        buttons.add(new JButton("Hello " + i));
                        buttons.revalidate();
                    }
                    return null;
                }
            };
            worker.execute();
        }
    }
    
    • 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 with a JTextArea set as its view port. I update
I currently have a JScrollPane in a JPanel. I have Images that are loaded
I have a JScrollPane with a JPanel that implements Scrollable as its viewport view.
I have designed a Swing form. It consists of a JScrollPane that itself contains
I have a JPanel that contains a JScrollPane that contains a JTable. Inside my
I have JScrollPane that contains a panel like JScrollPane scrollWindow = new JScrollPane(window); I
I have a simple JEditorPane inside a JScrollPane that displays line numbers on the
I have embedded a JTextArea on a JScrollPane and am using that JTextArea for
I have a ScrollPane and JTable that should only have one row of data.

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.