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 2 of 2

Thread: Problem with jList

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with jList

    Hello,
    I am very new to java, I have written some codes that has displayed a jList and jButton on a GUI. I have some text files (like assignment.txt etc) that I have saved in the same package with my source code. If I click a button, I want the .txt file to be read and displayed on the jList.

    I used buffered reader with AWT and it worked well for me. I simply used

    titlesList. add(c);

    where c is a String as shown below

    private void assignmentButtonActionPerformed(java.awt.event.Act ionEvent evt) {

    try
    {
    BufferedReader cla = new BufferedReader(new FileReader(assignment));
    String c;

    //read each line from a file

    while ((c = ass.readLine()) != null) {

    // THIS IS THE ADD C I USED
    titlesList.add(c);

    }
    cla.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    It is like Swing does not support add() method, PLEASE I NEED A CODE THAT WILL REPLACE titlesList.add(c); IN sWING SUCH THAT WHEN I CLICK ASSIGNMENT BUTTON, THE .txt THAT HAS ASSIGNMENT QUESTIONS WILL BE DISPLAYED ON A jList.
    THANK YOU.


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    491
    Thanks
    8
    Thanked 47 Times in 45 Posts

    Default Re: Problem with jList

    Read the API for JList and follow the link to the Swing tutorial on How to Use Lists where you will find a working example of adding and removing items from the JList at runtime.

    db

Similar Threads

  1. problem in getting scrollbar in Jlist
    By sandeepben in forum AWT / Java Swing
    Replies: 1
    Last Post: March 27th, 2010, 03:51 AM
  2. how to modify a JList Frame?
    By JM_4ever in forum AWT / Java Swing
    Replies: 0
    Last Post: October 14th, 2009, 11:58 PM
  3. Replies: 10
    Last Post: June 22nd, 2009, 07:45 AM
  4. [SOLVED] JAVA JList Problem in visual images
    By antitru5t in forum AWT / Java Swing
    Replies: 4
    Last Post: April 15th, 2009, 03:09 PM
  5. Dropping to graphic element dragged from JList
    By tua1 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 29th, 2008, 07:22 AM