Results 1 to 7 of 7
  1. #1
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default JLIST Extractions

    I have made two JLists that get data from a JTable when I click a button and now I need those JLists saved to another class or I could make new JLists and get the data from the previous JLists to implement. WHich way would be easier? Do you have an alternate solution? Show me how please.

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

    Default

    You might get a better answer if you tell us what problem you're trying to solve in a general sense rather than how you're trying to solve it.

  3. #3
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    I need to take JList data from one JList and put that data in either a JList or a JTable in another class.

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

    Default

    I'm still confused about your ultimate goal regardless of JLists and JTables, the meta-problem that is causing your question, I suppose. But if all you want to do is extract the data from one JList to use in another, then you could easily get the JList's model and set it as the model of your other JList. Jlist has get and set methods for this.

  5. #5
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    Thanks for the JList solution (thats one down) but I am also exploring the possibility of saving the values in my primary JList, saving it to a String array and then inputting that array into a JList column. This is what I want to happen. The user puts the data into the first JList then he clicks the continue button and that brings him onto a page showing all the JList data in one column of a JTable beside my other data. Thanks for your patience in trying to understand my dilemma.

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

    Default

    Once you have the model you could always iterate through it and place all the items, or their toString representations into an ArrayList<String> (I would favor using the more flexible ArrayList over an array since I'm guessing that the number of items could potentially change). You could give the class that holds the JList a public method to do this, something like (in semi-pseudo-code),

    Java Code:
    public ArrayList<String> getListData() {
        create a ListModel variable and assign it the JList's model
        Create an ArrayList<String> variable
        For loop with index, i, going from 0 to the model's size
           get the model's element at i and add to the array list
        end of for loop
        return the array list
    }

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Or if the model is a DefaultListModel, there's an API method that returns the data array.

    db

Similar Threads

  1. jList again
    By gmorris in forum Advanced Java
    Replies: 0
    Last Post: 01-05-2011, 12:25 PM
  2. Link one JList to another JList
    By mib1bee in forum AWT / Swing
    Replies: 1
    Last Post: 12-31-2010, 07:10 PM
  3. Link one JList to another JList
    By mib1bee in forum Advanced Java
    Replies: 1
    Last Post: 12-30-2010, 06:35 PM
  4. Link one JList to another JList
    By mib1bee in forum New To Java
    Replies: 1
    Last Post: 12-30-2010, 06:24 PM
  5. JList
    By nawl in forum New To Java
    Replies: 2
    Last Post: 05-21-2010, 06:37 AM

Tags for this Thread

Posting Permissions

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