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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:56:12+00:00 2026-05-29T13:56:12+00:00

I have the following code: package example; import java.awt.BorderLayout; import java.awt.FlowLayout; import javax.swing.JFrame; import

  • 0

I have the following code:

    package example;

    import java.awt.BorderLayout;
    import java.awt.FlowLayout;

    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;

    public class ScrollingExample extends JFrame
    {
        private static final long serialVersionUID = 1L;

        public static void main(String[] args)
        {
            ScrollingExample scrollingExample = new ScrollingExample();
            scrollingExample.go();
        }

        private void go()
        {
            JPanel topPanel = new JPanel();
            topPanel.add(new JLabel("boo"));

            JPanel mainPanel = new JPanel();
            JPanel mainInnerPanel = makeMainInnerPanel();

            JScrollPane scrollPane = new JScrollPane(mainInnerPanel);
            mainPanel.add(scrollPane);
            add(topPanel, BorderLayout.NORTH);
            add(mainPanel, BorderLayout.CENTER);

            pack();
            setVisible(true);
        }

        private JPanel makeMainInnerPanel()
        {
            JPanel row1 = makeHorizontalPanel("one", "two", "three", "four", "five");
            JPanel row2 = makeHorizontalPanel("six", "seven", "eight");
            JPanel row3 = makeHorizontalPanel("nine", "ten", "eleven");
            JPanel mainInnerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            mainInnerPanel.add(row1);
            mainInnerPanel.add(row2);
            mainInnerPanel.add(row3);
            return mainInnerPanel;
        }

        private JPanel makeHorizontalPanel(String ... labelValues)
        {
            JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            for (String s : labelValues)
            {
                JLabel label = new JLabel(s);
                panel.add(label);
            }
            return panel;
        }
    }

When I display it, it sizes itself to show all the labels; when I resize the window, I can’t get scrollbars to show up.

When I get this working, I want to make a panel that contains a JTabbedPane and a couple of buttons, and I want THAT to have scroll bars if the user sizes the window so that some part of it cannot be seen. If the answer to this question needs something additional or different to do that, mentioning it would be appreciated.

  • 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-29T13:56:16+00:00Added an answer on May 29, 2026 at 1:56 pm
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    
    public class ScrollingExample extends JFrame
    {
        private static final long serialVersionUID = 1L;
    
        public static void main(String[] args)
        {
            ScrollingExample scrollingExample = new ScrollingExample();
            scrollingExample.go();
        }
    
        private void go()
        {
                setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            JPanel topPanel = new JPanel();
            topPanel.add(new JLabel("boo"));
    
            JPanel mainPanel = new JPanel(new BorderLayout());
            JPanel mainInnerPanel = makeMainInnerPanel();
    
            JScrollPane scrollPane = new JScrollPane(mainInnerPanel);
            mainPanel.add(scrollPane);
            add(topPanel, BorderLayout.NORTH);
            add(mainPanel, BorderLayout.CENTER);
    
            pack();
            setVisible(true);
        }
    
        private JPanel makeMainInnerPanel()
        {
            JPanel row1 = makeHorizontalPanel("one", "two", "three", "four", "five");
            JPanel row2 = makeHorizontalPanel("six", "seven", "eight");
            JPanel row3 = makeHorizontalPanel("nine", "ten", "eleven");
            JPanel mainInnerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            mainInnerPanel.add(row1);
            mainInnerPanel.add(row2);
            mainInnerPanel.add(row3);
            return mainInnerPanel;
        }
    
        private JPanel makeHorizontalPanel(String ... labelValues)
        {
            JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            for (String s : labelValues)
            {
                JLabel label = new JLabel(s);
                panel.add(label);
            }
            return panel;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple Java code: package testj; import java.util.*; public class Query<T>
In the beginning of my Java code I have: import java.awt.BorderLayout; import java.awt.Container; import
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
I have the following code but the lon/lat seems to be returning null; package
I have a scala object defined like the following: package com.example object Foo {
Here is an example of the code I'm working on: package button { import
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My

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.