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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:55:22+00:00 2026-06-16T02:55:22+00:00

How to load a JList in horizontal fashion?? Here is my code,I am trying

  • 0

How to load a JList in horizontal fashion?? Here is my code,I am trying to display the JListsimilar to the screen shot provided.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.BorderLayout;
import java.io.File;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;

public class Test extends JFrame{

    private JList toolsList;
    private ArrayList<File> toolXmlList;

    public Test()
    {
    toolXmlList = new ArrayList<File>();
    toolXmlList = loadFiles();

    setVisible(true);
    setSize(300,300);
    setTitle("Test Jlist");
    createComponents();

    }

    public void createComponents()
    {
    toolsList = new JList();
    toolsList.setModel(displayDefaltTools());
    toolsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
    setLayout(new BorderLayout());
    add(toolsList,BorderLayout.CENTER);
    }

    /**
     * Creates a list model and add the tools to it
     *
     * @return DefaultListModel
     */
    public DefaultListModel displayDefaltTools() {
    DefaultListModel dlistModel = new DefaultListModel();
    String presentation = "";

    for (int i = 0; i < toolXmlList.size(); i++) {
        //System.out.println(idSet.get(i));
        presentation = presentation +  toolXmlList.get(i).getName() ;
        dlistModel.addElement(presentation);
        presentation = "";
    }
    return dlistModel;
    }

    public ArrayList loadFiles()
    {
    ArrayList<File> xmlFiles = new ArrayList<File>();
    File f = new File(".");
    File [] folList = f.listFiles();
    for(int i=0;i<folList.length;i++)
    {
        if(folList[i].getName().startsWith("Tool_Frag"))
        {
            File[] fileList=folList[i].listFiles();
            for(int j=0;j<fileList.length;j++)
            {
                System.out.println(fileList[j].getName());
                xmlFiles.add(fileList[j]);
            }
        }
    }
    return xmlFiles;
    }

    public static void main(String[] args)
    {
    new Test();
    }
}

I am trying to get a jlist in this manner,items displayed one next to another
screenshot on layout of jlist

  • 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-16T02:55:23+00:00Added an answer on June 16, 2026 at 2:55 am

    You will have to do two things:

    1. Set the LayoutOrientation to JList.HORIZONTAL_WRAP or JList.VERTICAL_WRAP as per the documentation.

    2. Make the list wide enough that it can display more than one element per row. Use setVisibleRowCount() for this.

      Calling setPreferredSize() also works but can cause trouble when you use layout managers.

    Alternatively, consider using a JTable if you must make sure a certain number of rows/columns (like all elements in a single line).

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

Sidebar

Related Questions

i am trying to load a .TIF formatted image to add into Jlist and
load.js: jQuery(document).ready(function($) { $('.dialog ul li').click(function(e) { switch($(this).attr('id')) { case 'addProject': $('.addDialog').load('/add/addprojectform'); break; case
I'm struggling while trying to write generic methods to save and load data from
I load a user control in a web page which throws an exception: this.LoadControl(someusercontrol);
I am trying to squash all the force closes in my program and here
I load a html page in web view in this way: NSString *description =
I load an SWF with SWFLoader. Within the loaded .SWF, this.parentApplication is returning NULL.
i have this code private ListView event_list; event_list = (ListView) open_event_list.findViewById(R.id.events_list); loadList(cw.getDate()); cw is
I am trying to load a file that I know part of the name
{% load comments %} where defined 'comments' ,a viewer? or a template?? thanks

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.