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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:00:16+00:00 2026-05-16T16:00:16+00:00

For some reason, I cannot this working. It should be simple really. I’ve having

  • 0

For some reason, I cannot this working. It should be simple really.

I’ve having a JFrame with a BorderLayout, which contains a JPanel (SOUTH) and a (CENTER) JPanel (itemPanel).

itemPanel should be wrapped in a scrollpane. Its width = x, and all of its children shares its length, so it basically works like a table with only 1 column.

For some reason, I cannot get the scrollpane to show the scrollbars (and scroll). In the JFrame:

setPreferredSize(dimension);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add("South",controlPanel);
JScrollPane scroll = new JScrollPane(itemPanel);
scroll.setBorder(null);
getContentPane().add("Center",scroll);
super.pack();
setVisible(true);

Initilizing and adding some dummy-panels to the itemPanel:

itemPanel = new ItemPanel(); // A JPanel with a flowlayout
itemPanel.setPreferredSize(new Dimension(dimension.width,0));
for(int i = 0; i < 20; i++){
  JPanel p = new JPanel();
  p.setPreferredSize(new Dimension(0,50));
  p.setBackground(i%2 == 0 ? Color.GREEN : Color.YELLOW);
  itemPanel.add(p);
}

if omitting itemPanel.setPreferredSize(new Dimension(dimension.width,0)); the scrollpane shows the horizontal scrollbars, but since the flowlayout does not have a width to follow, it just shows the components in one row.

  • 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-16T16:00:16+00:00Added an answer on May 16, 2026 at 4:00 pm

    A FlowLayout does NOT recalculate the preferred size of a panel. The scrollbars only appear when the preferred size of the component is greater than the size of the scroll pane.

    WrapLayout may be what you are looking for.

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

Sidebar

Related Questions

This is kind of embarrassing but I cannot for some reason get his CSS
For some reason the selected tab on TextMate is almost un-noticeable, I really cannot
I am working on this site: http://gitastudents.com/~clarkb/group1/Students.html For some reason it does not display
For some reason I get this: 1>LINK : fatal error LNK1104: cannot open file
I have a search setup inside a div but for some reason cannot get
For some reason I cannot seem to get a ko.computed observable to compute when
I use CSS transitions fairly regularly and for some reason I cannot get them
I want to use http://msdn.microsoft.com/en-us/library/aa370654%28VS.85%29.aspx in my code. But for some reason I cannot
It's a common problem, solved many times, but for some reason i cannot find
I declared a global shift operator but for some reason the compiler cannot deduct

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.