Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problem with Populating a List

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with Populating a List

    Hello. I am required to create a list of names in a form as part of a GUI. All the codes for creating the GUI have been done, the code for creating the form, scroll pane and a predefined list called M256JList.

    The constuctor of the class required had been created, I just add my code to make parts of it do stuff. The first was to create a method, and then add code to the constructor.

    First the method:

      //The methods in this section are concerned with the Borrow book screen
     
        /**
         * Populates the list of members.
         * Displays the membership numbers and
         * names of library members in ascending membership number order.
         * The first member is selected by default.
         */
        public void displayMembers()
        {
           initComponents();
           library = new LibraryCoord();
           Collection<Member> Member = library.getMembers();
           memberList.setListData(Member);
           memberList.setSelectedIndex(0);      
        }

    The constuctor with my added code:

    /** Creates new form LibraryGUI */
        public LibraryGUI()
        {
            initComponents();
            library = new LibraryCoord();
     
            // test fixture, adding members and books to library
            library = new LibraryCoord();
            library.addMember("Phil Archer");
            library.addMember("Nigel Pargetter");
            library.addMember("Jill Archer");
     
     
            library.addBook("Elements", "Euclid", Category.MATHS, 1);
            library.addBook("The Principia", "Newton", Category.MATHS, 2);
            library.addBook("The Design of Everyday Things", "Norman", Category.TECHNOLOGY, 3);
            library.addBook("The Art of Computer Programming", "Knuth",  Category.COMPUTING, 4);
     
            // TO DO (b)(ii)
     
            jScrollPane1.setViewportView(memberList);
     
        }

    The TO DO code is my addition.

    What is supposed to happen is that when I run the project the members' details are displayed in memberList, however this is not the case. What I get is the form with a list of lists i.e. list1, list2 etc.

    What have i done wrong?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Problem with Populating a List

    You haven't given us enough info. There's no way for us to know what the method displayMembers() is supposed to be doing.

    Post a short, runnable program that demonstrates the problem.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with Populating a List

    Quote Originally Posted by GregBrannon View Post
    You haven't given us enough info. There's no way for us to know what the method displayMembers() is supposed to be doing.

    Post a short, runnable program that demonstrates the problem.
    The method is meant to add the details from a list to a 'List box'. I guess the contstuctor adds the details to the display as well. The only progam I use to run it is NetBean so the provided constructor and method are run from it.

    As I understand it. The isea is to add the collection of library objects to the list object using setListData() and set the first element in the list to be selected by default.

    I hope that helps.

Similar Threads

  1. Populating a LinkedList in java
    By pyler in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 18th, 2014, 01:14 PM
  2. Populating multiple arrays with a File.
    By ccf in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2012, 09:11 PM
  3. Knapsack problem , check if matrix can fill list of smaller matrix list.
    By ofirattia in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 8th, 2012, 01:20 PM
  4. Populating a 2D array with textfield values
    By drixnak in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 19th, 2010, 01:20 PM
  5. Populating a JTable
    By crism85 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 20th, 2010, 01:57 PM