Results 1 to 2 of 2
  1. #1
    mutagen is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default How to print from Default List Model

    Heya guys so I've got a list of items in a default list model for example

    productlist = new ProductList();

    productlist.addProduct("01", "Apples", 1.45, "Fresh Green Apples", true);

    and I've got everything working but now I've got a button "Print all items"

    and it's supposed to print every single item or element in my productlist to screen, or a pop-up window either way I will know how to print them out. But i need a method to get all the elements from the list how do i achieve that? Do i use iterators? Or some one suggested using toString method but I'm not too familiar with them, maybe you guys have more elegant or easier solution?

    give me an example, thank you!

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    If you read the DefaultListModel API docs, you'll find an 'elements()' method that returns an Enumeration of all the items in the list. Alternatively, you can iterate over the list itself using the 'get(index)' method.

Similar Threads

  1. Copy Default table model to another default table model?
    By greatmajestics in forum AWT / Swing
    Replies: 2
    Last Post: 04-28-2010, 04:08 PM
  2. How to print the content of List
    By cassysumandak in forum New To Java
    Replies: 4
    Last Post: 10-01-2009, 10:36 AM
  3. Replies: 1
    Last Post: 03-10-2009, 01:12 PM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts