Results 1 to 3 of 3
  1. #1
    AnandVijay is offline Member
    Join Date
    Oct 2013
    Posts
    15
    Rep Power
    0

    Default How to add a dynamic values in JList ?

    Hi frnds !
    How to add a dynamic values in JList ?

  2. #2
    AnandVijay is offline Member
    Join Date
    Oct 2013
    Posts
    15
    Rep Power
    0

    Default Re: How to add a dynamic values in JList ?

    Java Code :

    DefaultListModel dl=(DefaultListModel) jList1.getModel();
    String str[]={"1","2","3"};
    dl.addElement(str);


    I tryd above one , but it will showing the following error!!!

    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: Index$2 cannot be cast to javax.swing.DefaultListModel

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,033
    Rep Power
    6

    Default Re: How to add a dynamic values in JList ?

    The problem is that the current model is not an instance of DefaultListModel so you get a class cast exception. You should add your own instance of DefaultListModel. And remember that JList and ListModel are generic types.

    Regards,
    Jim
    Last edited by jim829; 10-26-2013 at 06:46 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 4
    Last Post: 01-10-2012, 02:05 PM
  2. Link one JList to another JList
    By mib1bee in forum AWT / Swing
    Replies: 1
    Last Post: 12-31-2010, 08:10 PM
  3. Link one JList to another JList
    By mib1bee in forum Advanced Java
    Replies: 1
    Last Post: 12-30-2010, 07:35 PM
  4. Link one JList to another JList
    By mib1bee in forum New To Java
    Replies: 1
    Last Post: 12-30-2010, 07:24 PM
  5. Saving Values in a Dynamic UI
    By Nirmal_mm in forum Advanced Java
    Replies: 0
    Last Post: 01-25-2009, 07:23 AM

Posting Permissions

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