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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:10:15+00:00 2026-05-20T12:10:15+00:00

I have a JPanel where I draw shapes. this panel is added to a

  • 0

I have a JPanel where I draw shapes. this panel is added to a scrollPane. but the scrolling doesn’t work when a shape is out of the scene. is there an easy way to autoscroll or I have to do it programmatically.

Thank you

  • 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-20T12:10:15+00:00Added an answer on May 20, 2026 at 12:10 pm

    I’m assuming you’re using the JPanel as a canvas for custom drawing(i.e. you’re not adding any JComponents to it). If that’s case, the JScrollPane has no way of knowing how large the JPanel is and will just size it to exactly fill the scrollPane’s viewport(which means you’ll never actually get scroll bars).

    To fix this issue you should override getPreferredSize on your JPanel.

    @Override     
    public Dimension getPreferredSize() {
        int height = calculateHeight(); 
        int width = calculateWidth(); 
        return new Dimension(width, height);
    }
    

    Edit:

    Also, since you’re doing custom drawing make sure to call revalidate whenever the shapes you want to draw change. This tells swing that it needs to re-think the layout/size of the JPanel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code supposes to draw ring in random position within JPanel but for
How can i draw 2d in a JPanel that i have on my GUI?
I have a problem making an inner class that extends from JPanel to draw
I have a paint application and I draw on a JPanel. I want to
I have a JPanel that contains an image. I want to draw rulers on
I have 3 JPanel, the first is the base panel and the other two
I have a JPanel like this: GridBagConstraints constPanelInfo = new GridBagConstraints(); panelInfo = new
I have a component that inherits from JPanel, I draw a grid on it.
I just can't get this right. I have a slider to increase my JPanel's
I have a JPanel embedded inside a JFrame . JPanel is added at CENTER

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.