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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:42:49+00:00 2026-05-24T15:42:49+00:00

I have a Jlist like the one below. I am using the JList.HorizontalWrap to

  • 0

I have a Jlist like the one below. I am using the JList.HorizontalWrap to achieve this, but for some reason, after the 4th item in the list, it starts a new row.

Here is the configurations I used to get the list looking this.

        sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        sList.setVisibleRowCount(-1);
        sList.setLayoutOrientation(JList.HORIZONTAL_WRAP);

Is there any way I can set the List row count to be the width of the Jlist so that all items in the list will be set across before starting a new 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-24T15:42:52+00:00Added an answer on May 24, 2026 at 3:42 pm

    As I noted in my comment, your problem lends itself well to solving through creation of an SSCCE. In fact, I did one myself using your code snippet and some of my code:

    import java.awt.Dimension;
    import javax.swing.*;
    
    public class Foo001 {
    
       private static void createAndShowUI() {
          DefaultListModel model = new DefaultListModel();
          JList sList = new JList(model);
          for (int i = 0; i < 100; i++) {
             model.addElement("String " + i);
          }
    
          sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
          sList.setVisibleRowCount(-1);
          sList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    
          JFrame frame = new JFrame("Foo001");
          frame.getContentPane().add(new JScrollPane(sList));
          frame.getContentPane().setPreferredSize(new Dimension(400, 300));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    

    Since I cannot reproduce your problem with my code, I must conclude that your problem lies elsewhere in code that you’ve not shown us. Again, if you can create and post your SSCCE, we will likely be able to help answer your question, but until then, I’m not sure if we can even guess what the problem is.

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

Sidebar

Related Questions

I have a JList that holds a bunch of strings . I would like
I have a JList, and a JButton, user can click an item in the
I would like to create a JList in Java so that each individual item
http://pastebin.com/VaaTRsuf I would like to have the JList and JTextArea resize with the window,
I have a JList with a lot of items in it, of which one
Suppose that one has some lock based code like the following where mutexes are
Edit: Solved, I wasn't using 'validate()' after adding components. I have a GUI class
I have a JList and JTextArea pair. Based on the selected item on JList
I have a jlist of users. In which some user has presence 1st and
I have a JList with a DefaultListModel . How I can make an item

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.