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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:40:34+00:00 2026-05-31T14:40:34+00:00

How can I get the scroller around my JList component in the code given

  • 0

How can I get the scroller around my JList component in the code given below? It doesn’t seem to work properly 🙁

 public class JButtonO extends JFrame{

String[] values = {"henry", "Michael","Uche","John","Ullan","Nelly",
                              "Ime","Lekan","Austine","jussi","Ossi","Imam","Empo","Austine","Becky",
                             "Scholar","Ruth", "Anny"};

 public JButtonO()
{
   super("the button");
   this.setSize(400,200);
   JPanel panel =  new JPanel();
   JLabel label = new JLabel("Output Items:");
   label.setAlignmentX(1);
   label.setAlignmentY(1);
   JList conList = new JList(values);
   conList.setVisibleRowCount(3);
   JScrollPane scroller = new JScrollPane(conList);
   panel.add(label);
   panel.add(scroller);
   panel.add(conList);

   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   this.add(panel);
   this.setVisible(true);


}
  • 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-31T14:40:35+00:00Added an answer on May 31, 2026 at 2:40 pm

    Look, I may not answering what you need, because I don´t remember to much of swing layout. I don´t work with it a long time ago…

    But removing setting a layout (I remember) on your JPanel it works with this code:

    public JButtonO() {
        super("the button");
        this.setSize(400, 200);
    
        // Create a panel with a borderlayout
        JPanel jpanel = new JPanel(new BorderLayout());
    
        JLabel label = new JLabel("Output Items:");
        label.setAlignmentX(1);
        label.setAlignmentY(1);
        // Add Label to top of layout
        jpanel.add(label, BorderLayout.NORTH);
    
        JList conList = new JList(values);
        conList.setVisibleRowCount(3);
        JScrollPane scroller = new JScrollPane(conList);
        //AddScroll to center
        jpanel.add(scroller);
    
        //Add Panel to JFrame
        this.add(jpanel);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    
      }
    

    I think the problems is the default layoutmaneger of JPanel. Because of how it works your scroll was not “srink” enough to create scrolls…

    Hope it helps, even without too much explanation…

    ACTUALLY: After I post the answer I saw your mistake. Now I can explain what is wrong. You already added your JList inside your JScrollPane here:

    JScrollPane scroller = new JScrollPane(conList);
    

    But after that you put it inside the JPanel:

    panel.add(conList);
    

    this changes where yout JList will be displayed, and let the JScroll empty again. Without components it will be displayed with size 0x0 and will not be draw (even being there).

    Now I think I helped =D

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

Sidebar

Related Questions

Can't get it to scroll horizontally. What am I missing? Here's my code in
Is there a way to get the content of a component inside a scroller
Please, can anyone help me out on this : the piece of code below
Can get all triples with value null in specific field? All people with date_of_birth
You can get underground processes by ps ux I am searching a way to
You can get a list of databases using PRAGMA database_list or a list of
I can get the current selected row in this way: private void DataGridView1_CellContentClick(object sender,
I can get the the first row in a ListView item in .NET 3.5
I can get the word under the cursor with or , and I can
I can get the unique id like className@2345 of my object by calling its

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.