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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:15:54+00:00 2026-06-05T23:15:54+00:00

I want to add multiple jpanels to jpanel.So i added a root panel to

  • 0

I want to add multiple jpanels to jpanel.So i added a root panel to jscrollpane.and then added all individual jpanels to this root panel.I made jscrollpane’s scrolling policy as needed.i.e HORIZONTAL_SCROLLBAR_AS_NEEDED,VERTICAL_SCROLLBAR_AS_NEEDED.
But the problem is all individual panels are not shown inside root panel.

Code:

JScrollPane scPanel=new JScrollPane();

JPanel rootPanel=new JPanel();
rootPanel.setLayout(new FlowLayout());

JPanel indPanel = new JPanel();
rootPanel.add(indPanel);

JPanel indPanel2 = new JPanel();
rootPanel.add(indPanel2);

//.....like this added indPanals to rootPanel.
scPanel.setViewPortView(rootPanel);
//scPanel.setHorizontalScrollPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED);

And one more thing is, as i scroll the scrollbar the panels are going out of jscrollpane area.
I am not able to see all individual panels,
Please suggest me.

Edit: code snippet from double post:

MosaicFilesStatusBean mosaicFilesStatusBean = new MosaicFilesStatusBean();
DefaultTableModel tableModel = null;
tableModel = mosaicFilesStatusBean.getFilesStatusBetweenDates(startDate, endDate);
if (tableModel != null) {
    rootPanel.removeAll();        
    rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS));      
    for (int tempRow = 0; tempRow < tableModel.getRowCount(); tempRow++) {

        int fileIdTemp = Integer.parseInt(tableModel.getValueAt(tempRow, 0).toString());
        String dateFromTemp = tableModel.getValueAt(tempRow, 3).toString();
        String dateToTemp = tableModel.getValueAt(tempRow, 4).toString();
        int processIdTemp = Integer.parseInt(tableModel.getValueAt(tempRow, 5).toString());
        int statusIdTemp = Integer.parseInt(tableModel.getValueAt(tempRow, 6).toString());
        String operatingDateTemp = tableModel.getValueAt(tempRow, 7).toString();                
        MosaicPanel tempPanel =           
           new MosaicPanel(fileIdTemp, dateFromTemp, dateToTemp, processIdTemp, statusIdTemp, operatingDateTemp);             
        rootPanel.add(tempPanel);             
    }
    rootPanel.revalidate();
}
  • 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-06-05T23:15:56+00:00Added an answer on June 5, 2026 at 11:15 pm

    The main reason, why you couldn’t see your JPanel is that you are using FlowLayout as the LayoutManager for the rootPanel. And since your JPanel added to this rootPanel has nothing inside it, hence it will take it’s size as 0, 0, for width and height respectively. Though using GridLayout such situation shouldn’t come. Have a look at this code example attached :

    import java.awt.*;
    import javax.swing.*;
    
    public class PanelAddition
    {
        private void createAndDisplayGUI()
        {
            JFrame frame = new JFrame("Panel Addition Example");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            JPanel contentPane = new JPanel();
            contentPane.setLayout(new GridLayout(0, 1));        
            JScrollPane scroller = new JScrollPane();
    
            CustomPanel panel = new CustomPanel(1);
            contentPane.add(panel);
            scroller.setViewportView(contentPane);
            frame.getContentPane().add(scroller, BorderLayout.CENTER);
            frame.pack();
            frame.setLocationByPlatform(true);
            frame.setVisible(true);
    
            for (int i = 2; i < 20; i++)
            {
                CustomPanel pane = new CustomPanel(i);
                contentPane.add(pane);
                contentPane.revalidate();
                contentPane.repaint();
            }
        }
    
        public static void main(String... args)
        {
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    new PanelAddition().createAndDisplayGUI();
                }
            });
        }
    }
    
    class CustomPanel extends JPanel
    {
    
        public CustomPanel(int num)
        {
            JLabel label = new JLabel("" + num);
            add(label);
        }
    
        @Override
        public Dimension getPreferredSize()
        {
            return (new Dimension(200, 50));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add multiple borders on a single image. Is this possible through
I want add my custom sidebar next right column all page. Please check this
I want to add multiple BigInteger values to an ArrayList . All I have
I want to add multiple jinja2 etensions but I don't know the syntax. This
in order to make things easier for users i want to add multiple keyword
Hi In my application I am using SQLITE database, I want to add multiple
I want to add a class to multiple span elements with common classname's based
I want to show multiple detail section in my jasper report. How to add
I want add new Feed item on entity persist and update. I write this
I want to add multiple methods in that respond as the selector when 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.