Results 1 to 4 of 4
  1. #1
    amitabh is offline Member
    Join Date
    Apr 2010
    Posts
    51
    Rep Power
    0

    Default Problem With jList

    Hello every one I want to add element in jList by returning database and collect in a String array.
    but wahen i add element like jList.addElement(string[i]);
    it gives error. here i is for loop variable.
    The same thing work fine with jComboBox;.addItem(string[i]);
    Please tell me where is the problem and what is method i have to use.
    Thank you.

  2. #2
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    I dont know much about the JList, I've never used it.
    I did have a brief look at the java docs, and it looks like you should add the list of strings in the constructor:

    Java Code:
    JList aList = new JList (string[]);
    No need for any loops :)

    Alternatively it looks like you could use

    Java Code:
    aList.setListData(string[]);
    As I said I've never used JList before so I may be wrong.

    Hope this helps!
    Berkeleybross

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by amitabh View Post
    ...
    but wahen i add element like jList.addElement(string[i]);
    it gives error. here i is for loop variable.
    ....Please tell me where is the problem and what is method i have to use.
    It would help greatly if you were to show more of your code and show the exact error message. Otherwise all we can do is guess what is wrong.

  4. #4
    amitabh is offline Member
    Join Date
    Apr 2010
    Posts
    51
    Rep Power
    0

    Default

    Quote Originally Posted by berkeleybross View Post
    I dont know much about the JList, I've never used it.
    I did have a brief look at the java docs, and it looks like you should add the list of strings in the constructor:

    Java Code:
    JList aList = new JList (string[]);
    No need for any loops :)

    Alternatively it looks like you could use

    Java Code:
    aList.setListData(string[]);
    As I said I've never used JList before so I may be wrong.

    Hope this helps!
    Berkeleybross
    Thank y sir
    your code aList.setListData(string[]); is working correctly and my problem has been solved
    Thank Again

Similar Threads

  1. [SOLVED] JList( Vector ) Display problem
    By logicbug in forum AWT / Swing
    Replies: 4
    Last Post: 03-21-2009, 03:28 PM
  2. JList
    By pinks_70986 in forum New To Java
    Replies: 1
    Last Post: 02-12-2009, 09:36 AM
  3. JList and records, what to do to solve the problem
    By willemjav in forum Java Applets
    Replies: 10
    Last Post: 06-11-2008, 03:28 PM
  4. Problem with JComboBox and Jlist
    By java_fun2007 in forum New To Java
    Replies: 2
    Last Post: 05-07-2008, 09:58 PM
  5. JList problem
    By zizou147 in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 09:50 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
  •