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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:46:34+00:00 2026-06-01T04:46:34+00:00

I have a JFrame which consists only of a JList , the JList has

  • 0

I have a JFrame which consists only of a JList, the JList has its own cell renderer, in the cell renderer a JTextPane is returned with a custom size. The custom size has the result that the lines of this text panes are wrapped.

textPane.setSize(WIDTH, HEIGHT);

Now I want to make this JList scrollable, so I wrap it into a JScrollPane component, this however, nullifies the width constraints I have defined in the cell renderer. What would be the best way to enforce the width constraint in the JScrollPane?

setSize(FRAME_WIDTH, FRAME_HEIGHT);
setLayout(new BorderLayout());

DefaultListModel<Status> listModel = new DefaultListModel<Status>();
JList<Status> list = new JList<>(listModel);
list.setLayout(new BorderLayout());
list.setSize(FRAME_WIDTH, FRAME_HEIGHT);
list.setCellRenderer(new MyCellRenderer());
// wrap the list with a JScrollPane
add(new JScrollPane(list), BorderLayout.CENTER);
  • 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-01T04:46:36+00:00Added an answer on June 1, 2026 at 4:46 am

    The render operation of Cell is done by javax.swing.plaf.basic.BasicListUI class, and it will paint whole case, no matter what size you set for cell renderer. You can dig into the source code of BasicListUI class to understand how it works.

    I guess you just to make sure the content of the cell can be all displayed. In this case, you can add a horizontal scroll bar for the list. To do this, get a preferred width for the list.

    Like below:

    public static void main(String[] args)
    {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setSize(800, 600);
    
        JList list = new JList(new Object[]{ "11", "22" })
        {
            @Override
            public Dimension getPreferredSize()
            {
                return new Dimension(1000, 800);
            }
        };
        frame.getContentPane().add(new JScrollPane(list), BorderLayout.CENTER);
    
        frame.setVisible(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JFrame which on instantiation calls a custom JDialog(Login). If login is
I have a JFrame(frm) in which I've added a JPanel (pnl1)..which in turn has
I have a JFrame which has 3 JPanels in GridBagLayout .. Now, when I
I have a main JFrame which consists of 3 small JPanel which are switched
I have created my own WYSIWYG editor which consists of a design window and
Consider the following scenario: I have a JFrame Main which has a jButton caravanDataButton
I have an application which consists mainly in a JList being displayed on the
So I have a JFrame , in which it has a bunch of JPanel
Hi everyone I have a JFrame which has three components inside. A menu A
So I have created this JFrame window which has a lot of items like

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.