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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:37:56+00:00 2026-06-15T07:37:56+00:00

I have a JList that I need to Place inside a scroll Pane because

  • 0

I have a JList that I need to Place inside a scroll Pane because I am getting the JList from the database and the values can increase greatly. I need to be able to scroll them down so I wrote:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class Checkboxlistener extends JFrame {

private JPanel jpAcc = new JPanel();
private JList checkBoxesJList;

Checkboxlistener() {
   // super("Deposit base", false, true, false, true);
    setSize(1300, 600);
    jpAcc.setLayout(null);
    jpAcc.setBackground(Color.LIGHT_GRAY);
    String labels[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
    checkBoxesJList = new JList(labels);

    checkBoxesJList.setBounds(10, 30, 80, 600);
    checkBoxesJList.setBackground(Color.LIGHT_GRAY);
    checkBoxesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane scrollPane = new JScrollPane(checkBoxesJList);

    jpAcc.add(checkBoxesJList);
    jpAcc.add(scrollPane);



    getContentPane().add(jpAcc);
    setVisible(true);
}

public static void main(String args[]) {
   Checkboxlistener cbl = new Checkboxlistener();
}
}

What Am I doing wrong because I do not see any ScrollPane?

  • 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-15T07:37:57+00:00Added an answer on June 15, 2026 at 7:37 am

    The list is already contained inside the scrollpane, so you must not add the list to the main panel. Only the scroll pane.

    Another thing you’re doing wrong is not using a layout manager, and setting the bounds and sizes of your components. Don’t do that. Let the layout manager position and size the components for you.

    And finally, you shouldn’t use Swing components from the main thread. Only in the event dispatch thread.

    Here’s a modified version of your code that works fine. I removed the background colors, as this should be handled by the L&F:

    public class Checkboxlistener extends JFrame {
    
        private JPanel jpAcc = new JPanel();
        private JList<String> checkBoxesJList;
    
        Checkboxlistener() {
            jpAcc.setLayout(new BorderLayout());
            String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
            checkBoxesJList = new JList<String>(labels);
    
            checkBoxesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            JScrollPane scrollPane = new JScrollPane(checkBoxesJList);
    
            jpAcc.add(scrollPane);
    
            getContentPane().add(jpAcc);
            pack();
        }
    
        public static void main(String args[]) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    Checkboxlistener cbl = new Checkboxlistener();
                    cbl.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 simple example of a JList that is getting it's data from
I have a JList with items that I want to show two values. Is
I have a program that need to update the content of JList , which
I have a JList that is inside of a JscrollPane and I am trying
I have a list of Customer objects that I need to have selectable from
I have this JList that I'm using as the display for System.out . I'm
I'm making a swing based application where I have a JList that periodically get's
I have a JList, and a JButton, user can click an item in the
I have a JList inside a Scrollpane. If you click on the list and
I have a JList which uses a DefaultListModel. I then add values to the

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.