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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:16:20+00:00 2026-06-09T22:16:20+00:00

I am trying to add a JList to my layout (2 column layout). When

  • 0

I am trying to add a JList to my layout (2 column layout). When added, it makes its entire column take over the entire width of the parent JFrame:

LwjglCanvas c = new LwjglCanvas(blah);
c.getCanvas().setMaximumSize(new Dimension(480, 800)); // explicit width

Box h = Box.createHorizontalBox();
h.add(c.getCanvas());
Box v = Box.createVerticalBox();
h.add(v);
JList list = new JList(mDefaultListModel); // plz use remainder width
v.add(list);

JFrame frame = new JFrame();
frame.setMinimumSize(new Dimension(800, 800));
frame.add(h);
frame.pack();
frame.setVisible(true);

So with the JList added, the right column expands to the full width of the JFrame. I tried wrapping the JList in a JScrollPane, but then my seems to hang upon creation and layout never completes.

What’s the right way to do this?

Thanks

—— Update ————–

I’m giving the JList a bunch of String instances as its data. The strings happen to be pretty long. It looks like what’s happening is that the JList is making itself as wide as the longest string it has to render, ignoring all other layout params. Ideally it would just horizontally scroll instead of growing to the maximum possible width necessary.

—— Update ————–

Finally figured out what was going on. Specifying the size of the JFrame seems to have been causing this behavior. As soon as I removed that line, the JList started rendering as expected. Wrapped it in a JScrollPane, works now too.

  • 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-09T22:16:21+00:00Added an answer on June 9, 2026 at 10:16 pm

    Add glue to the layout. Glue will take up the rest of the panel width that’s not being used by your components. So put this line of code in the spot you want taking up the rest of the room in the panel:

    h.add(Box.createHorizontalGlue());
    

    Also, as noted in the comments of the question, with the BoxLayout you don’t need any positioning information. So you can simply use this:

    h.add(someOtherPanel);

    instead of this:

    h.add(someOtherPanel, BorderLayout.WEST);

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

Sidebar

Related Questions

I'm trying to add items to a JList asynchronously but I am regularly getting
I'm trying to add a scrollbar to a JList (which uses a custom data
I am trying to add JList component to panel but the list look weird
I'm trying to add element from a Jlist to another , append if this
i am trying to load a .TIF formatted image to add into Jlist and
I'm trying add data triggers to the default combobox style so each text item
I am trying add picture boxes dynamically. My code is as PictureBox picture =
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add init parameter names to a list in init(ServletConfig) method. public void
Trying to add a blank sample app for a rails tutorial to GitHub, but

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.