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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:10:32+00:00 2026-05-24T09:10:32+00:00

I have a JPanel inside the JScrollPane and it does that whenever I try

  • 0

enter image description here

I have a JPanel inside the JScrollPane and it does that whenever I try to scroll. Please help! How do I fix this?

EDIT

JScrollPane pane;
....
pane = new JScrollPane(GC.createGraph());
pane.setPreferredSize(new Dimension(480,480*2/3));
  • 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-24T09:10:32+00:00Added an answer on May 24, 2026 at 9:10 am

    Placing as an answer for others to see. If you don’t call the super.paintComponent, you’ll get those artifacts. e.g.,

    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    
    import javax.swing.*;
    
    public class ScrollPaneArtifacts extends JPanel {
       private static final int SPA_WIDTH = 600;
       private static final int SPA_HEIGHT = SPA_WIDTH;
    
       @Override
       protected void paintComponent(Graphics g) {
          //super.paintComponent(g);
          g.setColor(Color.red);
          g.drawLine(0, 0, getWidth(), getHeight());
          g.drawLine(getWidth(), 0, 0, getHeight());
       }
    
       @Override
       public Dimension getPreferredSize() {
          return new Dimension(SPA_WIDTH, SPA_HEIGHT);
       }
    
       private static void createAndShowUI() {
          JScrollPane scrollpane = new JScrollPane(new ScrollPaneArtifacts());
          scrollpane.getViewport().setPreferredSize(new Dimension(400, 400));
          JFrame frame = new JFrame("ScrollPaneArtifacts");
          frame.getContentPane().add(scrollpane);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    • 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 JPanel that contains a JScrollPane that contains a JTable. Inside my
I have a JPanel with a GridBagLayout inside of a JScrollPane. I also have
I have a JScrollPane and JPanel inside it(I want to draw on JPanel). Also
I have a JScrollPane and a JPanel inside. I see the scrollbars when needed,
I have a JPanel that holds a JScrollPane that holds a JPanel as such:
I have a JPanel that encapsulates two JPanels, one on top of the other.
I have a JFrame that contains a display JPanel with JTextField and a control
I have a Graphics object of JPanel and that is working fine: import java.awt.Color;
I have a JPanel sitting inside the center position of a BorderLayout of a

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.