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

  • Home
  • SEARCH
  • 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 9165681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:57:46+00:00 2026-06-17T14:57:46+00:00

I am implementing a program for a Component Design course and am currently struggling

  • 0

I am implementing a program for a Component Design course and am currently struggling with what should be simple use of a Jlist. The program draws shapes and should display them in a JList in a ScrollPane in the BorderLayout.West of the frame.

The current program shows the ScrollPane but will not display objects I add to the shapeListModel like it should. I am wondering it I am missing something or if something is flat out wrong with my code. Currently this is all the code that partains to the JList creation, assigning, and updating.

    //Class Variable Declaration
protected ArrayList<Shape> shapes = new ArrayList<Shape>();
private JScrollPane shapeScrollPane = new JScrollPane();
private JList<String> shapeList;
protected DefaultListModel<String> shapeListModel;

    //Creation of JList objects and what not
shapeListModel = new DefaultListModel<String>();

    //This element is added aimply to try and get one to show up on my JList, 
shapeListModel.addElement("SERIOUSLY FRUSTRATED"); 
    //It does not just so you know

shapeList = new JList<String>(shapeListModel);
shapeList.setModel(shapeListModel);

    //Adding JList to ScrollPane and setting size
shapeScrollPane.add(shapeList);
shapeScrollPane.setPreferredSize(new Dimension(250,600));

//Clarifying JList actions  
shapeList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
shapeList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
shapeList.setVisibleRowCount(-1);
shapeList.addListSelectionListener(this);**

    //This is called everytime a new shape is created and adds it to the Arraylist
    //shapes and the DefaultListModel shapeListModel
shapes.add(newShape);
shapeListModel.addElement(newShape.toString());

I apologize for my poorly formatted question a few moments ago. I have been stuck on this for approximately 4 hours, the last two hours spent searching for answers online. I am now resulting to asking anyone if they see an issue within the code I have.

  • 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-17T14:57:47+00:00Added an answer on June 17, 2026 at 2:57 pm

    You don’t “add” components a scroll pane. You need to set it’s view ports view instead.

    Don’t do this…

    shapeScrollPane.add(shapeList);
    

    Do this…

    shapeScrollPane.setViewportView(shapeList);
    

    Check out

    • How to use Scroll Panes
    • JScrollPane#setViewportView

    Also, this shapeList.setVisibleRowCount(-1) scares me to no end.

    Updated

    You also don’t need to this…

    shapeList = new JList<String>(shapeListModel);
    shapeList.setModel(shapeListModel);
    

    This is more then sufficient…

    shapeList = new JList<String>(shapeListModel);
    

    Updated

    Also, if this is the same code that was used in a previously closed question…

    This canvas.getGraphics() terrifies me!! If your instructor gave you this code, then they shouldn’t be teaching you!

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

Sidebar

Related Questions

I need to write a program implementing the visitor design pattern. The problem is
I'm implementing a c# program that should automatize a Mono-alphabetic substitution cipher. The functionality
Im implementing ITU standard based loudness measurement program and as it states i should
I have to write a program who use collection for implementing a map in
I am writing my own shell program. I am currently implementing the cd command
I am implementing both server and client side of a simple file download program.
I am currently implementing a program that requires me to handle threads and process.
I am currently working on implementing a program based on the huffman algorithm in
I'm implementing a simple RMI Server Client program in JAVA. I'm new to this
I am confused about using php or python for implementing server program . I

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.