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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:25:11+00:00 2026-05-14T19:25:11+00:00

I have a JScrollpane that has a JPanel on the inside (and the panel

  • 0

I have a JScrollpane that has a JPanel on the inside (and the panel contains some JLabels).

I want resizing the scroll pane to actually change its size (possibly below the preferred size of the inner components), not just the size of the viewport.

The goal is for the inner panel to gracefully disappear (using specific shrink priorities and the like in my miglayout) when the user shrinks the scrollpane too small.

  • 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-14T19:25:12+00:00Added an answer on May 14, 2026 at 7:25 pm

    Probably the best method is to have the contained component always be the same width as the viewport. To do this the first contained component (the one that is the child to JViewPort, passed into the JScrollPane constructor or set as the viewportView) needs to implement javax.swing.Scrollable. The key method is getScrollableTracksViewportWidth, which should return true.

    Here’s a quick and dirty scrollable JPanel :

    public class ScrollablePanel extends JPanel implements Scrollable {
        public Dimension getPreferredScrollableViewportSize() {
            return getPreferredSize();
        }
    
        public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
           return 10;
        }
    
        public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
            return ((orientation == SwingConstants.VERTICAL) ? visibleRect.height : visibleRect.width) - 10;
        }
    
        public boolean getScrollableTracksViewportWidth() {
            return true;
        }
    
        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 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 JScrollPane and JPanel inside it(I want to draw on JPanel). Also
I have a JScrollPane , which has a JPanel for its content pane. To
I have JScrollPane that contains some images in a horizontal row. If the row
I have a simple JEditorPane inside a JScrollPane that displays line numbers on the
I have a JFrame with JScrollPane in it. I have JPanel inside a scrollPane.
I want to have a JEditorPane inside a JScrollPane. When the user clicks a
I have a JPanel panel which contains a JTree tree . Sometimes the JTree
I have created a JPanel which contains an arbitrary number of JLabels, laid out

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.