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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:50:22+00:00 2026-05-22T16:50:22+00:00

I have a JScrollPane with a very high JPanel inside, that is changed dynamically,

  • 0

I have a JScrollPane with a very high JPanel inside, that is changed dynamically, items being appended at its end. What I want, is to scroll to the bottom of aforementioned JScrollPane in order for the newly appended items to be visible instantly on addition (they are not appended to the scroll pane directly, but to its JPanel, and are private objects, so cannot be referenced.

How can I simply have that scroll pane scroll to the very bottom?
Thanks in advance!

  • 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-05-22T16:50:22+00:00Added an answer on May 22, 2026 at 4:50 pm

    JComponent.scrollRectToVisible(Rectangle). Call that on the JPanel instance.

    E.G.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    class ScrollToNewLabel {
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater( new Runnable() {
                public void run() {
                    JPanel gui = new JPanel(new BorderLayout(3,3));
                    final JPanel panel = new JPanel(new GridLayout(0,1));
                    JScrollPane scroll = new JScrollPane(panel);
                    scroll.setPreferredSize(new Dimension(80,100));
                    gui.add(scroll, BorderLayout.CENTER);
                    JButton addLabel = new JButton("Add Label");
                    gui.add(addLabel, BorderLayout.NORTH);
                    ActionListener listener = new ActionListener() {
                        int counter = 0;
                        public void actionPerformed(ActionEvent ae) {
                            panel.add(new JLabel("Label " + ++counter));
                            panel.revalidate();
                            int height = (int)panel.getPreferredSize().getHeight();
                            Rectangle rect = new Rectangle(0,height,10,10);
                            panel.scrollRectToVisible(rect);
                        }
                    };
                    addLabel.addActionListener(listener);
                    JOptionPane.showMessageDialog(null, gui);
                }
            });
        }
    }
    

    Screen shot

    enter image description here

    E.G. 2

    This e.g. is based on Vincent’s answer, to use JScrollPane.getVerticalScrollBar().setValue(height). Where height is the preferred height of the panel in pixels.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    class ScrollToNewLabel {
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater( new Runnable() {
                public void run() {
                    JPanel gui = new JPanel(new BorderLayout(3,3));
                    final JPanel panel = new JPanel(new GridLayout(0,1));
                    final JScrollPane scroll = new JScrollPane(panel);
                    scroll.setPreferredSize(new Dimension(80,100));
                    gui.add(scroll, BorderLayout.CENTER);
                    JButton addLabel = new JButton("Add Label");
                    gui.add(addLabel, BorderLayout.NORTH);
                    ActionListener listener = new ActionListener() {
                        int counter = 0;
                        public void actionPerformed(ActionEvent ae) {
                            panel.add(new JLabel("Label " + ++counter));
                            panel.revalidate();
                            int height = (int)panel.getPreferredSize().getHeight();
                            scroll.getVerticalScrollBar().setValue(height);
                        }
                    };
                    addLabel.addActionListener(listener);
                    JOptionPane.showMessageDialog(null, gui);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JScrollpane that has a JPanel on the inside (and the panel
I have a JScrollpane which contains a scrollable client that changes its size dynamically
I have a JScrollPane with a JPanel that implements Scrollable as its viewport view.
I have a JScrollPane and JPanel inside it(I want to draw on JPanel). Also
I have a JFrame with JScrollPane in it. I have JPanel inside a scrollPane.
I have a simple JEditorPane inside a JScrollPane that displays line numbers on the
I want to have a JEditorPane inside a JScrollPane. When the user clicks a
I have a JList nested inside of a JScrollPane. When I add items to
I have a JScrollPane with FlowLayout that I want to have a fixed width.
I currently have a JScrollPane in a JPanel. I have Images that are loaded

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.