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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:55:33+00:00 2026-05-22T15:55:33+00:00

I have made a program with a scroll pane, but it is not working.

  • 0

I have made a program with a scroll pane, but it is not working. Please look at the source code:

JInfoView.java

package view;
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class JInfoView extends JPanel {
    private JButton button = new JButton("ADD");
    private JButton buttonDelete = new JButton("DEL");
    private JTextField input = new JTextField("Text", 5);
    private JLabel label = new JLabel("Test");
    public JInfoView() {
        this.setLayout(new FlowLayout());
        this.add(button);
        this.add(buttonDelete);
        this.add(input);
        this.add(label);
    }
}

JMainView.java

package view;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import view.JInfoView;

public class JMainView extends JFrame {
    private JPanel mypanel = new JPanel(new GridLayout(0, 1, 30, 50));
    private JScrollPane scrollPane = new JScrollPane(mypanel);
    public JMainView() {
        super("Simple Example");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Container container = this.getContentPane();
        container.setLayout(new FlowLayout());
        container.add(scrollPane);

        scrollPane.setVisible(true);
        scrollPane.setAutoscrolls(true); 

        mypanel.add(new JInfoView());
        mypanel.add(new JInfoView());
        mypanel.add(new JInfoView());       
        mypanel.add(new JInfoView());
        mypanel.add(new JInfoView());
        mypanel.add(new JInfoView());
        mypanel.add(new JInfoView());
        mypanel.add(new JInfoView()); 
        mypanel.add(new JInfoView());
    }

    public static void main(String[] args) {
        JMainView app = new JMainView();
        app.setVisible(true);
    }
}

I’ve read a tutorial which says:

//In a container that uses a BorderLayout:
textArea = new JTextArea(5, 30);
...
JScrollPane scrollPane = new JScrollPane(textArea);
...
setPreferredSize(new Dimension(450, 110));
...
add(scrollPane, BorderLayout.CENTER);

I’ve done the same steps,

private JPanel mypanel = new JPanel(new GridLayout(0, 1, 30, 50));
private JScrollPane scrollPane = new JScrollPane(mypanel);

And then added scrollpane:

container.add(scrollPane);

Where is a mistake?
EDIT:
The problem is that the scroll pane is not working. I add many JInfoView to the mypanel,
but scroll is not working..

  • 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-22T15:55:33+00:00Added an answer on May 22, 2026 at 3:55 pm

    You have forgotten to add scrollPane.setPreferredSize call like this:

    public class JMainView extends JFrame {
        private JPanel mypanel = new JPanel(new GridLayout(0, 1, 30, 50));
        private JScrollPane scrollPane = new JScrollPane(mypanel);
        public JMainView() {
            super("Simple Example");
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            Container container = this.getContentPane();
            container.setLayout(new FlowLayout());
            container.add(scrollPane);
    
            scrollPane.setVisible(true);
            scrollPane.setAutoscrolls(true);
            scrollPane.setPreferredSize(new Dimension(300, 400)); //========== this was missed
    
            mypanel.add(new JInfoView());
            mypanel.add(new JInfoView());
            mypanel.add(new JInfoView());
            mypanel.add(new JInfoView());
            mypanel.add(new JInfoView());
            mypanel.add(new JInfoView());
            mypanel.add(new JInfoView());
            mypanel.add(new JInfoView());
            mypanel.add(new JInfoView());
            this.pack();
        }
    
        public static void main(String[] args) {
            JMainView app = new JMainView();
            app.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have made a program to compute roots of quauation but it does not
I have made strstr() function but the program does not give any output,just a
I have made a program in Java that calculates powers of two, but it
My C++ is a little rusty but I have made a program that reverses
I have made a program in Java which is used to collect medical data
I have made a program in C# 2010 and my code contains a Tuple,
I have made a little program in java that accepts a string as a
I have made some c code for a program, which does some psycho-acoustics on
I have made a program on eclipse. But how can I get the program
I have made a program in c and wanted to see, how much memory

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.