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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:14:29+00:00 2026-05-27T16:14:29+00:00

below is my code for creating the JList. When it is created in a

  • 0

below is my code for creating the JList. When it is created in a standalone JFrame the JList fills the entire frame. However, when I create it as a JPanel and add it to the JFrame it is not filling the size of the component, Why?

public class ListBranchesInterface extends JPanel {
private Library theLibrary; // reference to back end
private ArrayList<LibraryBranch> branches;
private DefaultListModel dlm;
private JList list;
private JScrollPane scroll;

public ListBranchesInterface(Library theLibrary) {
    this.theLibrary = theLibrary;
    branches = new ArrayList<LibraryBranch>();
    branches.addAll(theLibrary.getLibraryBranches());

    Iterator<LibraryBranch> iter = branches.iterator();
    dlm = new DefaultListModel();
    while (iter.hasNext()) {

        dlm.addElement(iter.next().toString());

    }
    list = new JList(dlm); // create a JList from the default list model

    scroll = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); // add a scroll pane
                                                        // to the JList

    add(scroll);
    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-27T16:14:30+00:00Added an answer on May 27, 2026 at 4:14 pm

    Because the default layout manager of a JFrame‘s content pane is BorderLayout and adding directly to it would fill the entire available space (i.e., center) of the frame’s content pane. On the other hand, the default layout manager of a JPanel is FlowLayout. The FlowLayout class puts components in a row, sized at their preferred size. So adding the JList to a JPanel would not fill the entire available space.

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

Sidebar

Related Questions

I am creating a view and written the below code snippet : CREATE OR
The below code works great for creating Unique Constraints : ALTER TABLE <tablename> ADD
I am creating a chunk of HTML/JavaScript with the below code: $result = mysql_query(SELECT
I am creating a random ID using the below code: from random import *
The below code seems like it should work; however, the blob in the database
Below is my code for creating a symlink of a directory: sudo ln -s
Please check the below code, where I am creating multiple reference for an array
I consistently get the error 'failed creating formpost data' from the below code, the
please tell me what is below code doing? is it creating array with two
In my android app I've got the below code creating my database. This works

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.