javalistlistmodel

How to transfer one ListModel into an other one in Java


I have two ListModels: listModelRight und listModelLeft. I just want, that listModelRight = ListModelLeft, but even this dont work. How can i do it?

Code Example:

listModelFilterleft = listModelFilterright;
jList10.setModel(listModelFilterleft);
listModelFilterright.clear();
jList11.setModel(listModelFilterright);

For more Information why: I trying to make a Filter, consisting out of two JLists and 5 Buttons. The Buttons are to put the Filtervariables from the left to the right or back again. 5 Buttons mean:

> from left to right
>> all from left to right
<> change left and right
<< all from right to left
< from right to left

If you click on >> or << all Items should go from the on list to the other list. Because of this, i will use the original Inputitems (in the correct order), which i used to fill the list with items...


Solution

  • listModelFilterleft = listModelFilterright;
    

    So now, these two variables reference the same, unique object.

    List10.setModel(listModelFilterleft);
    

    The first list uses that unique object as its model

    listModelFilterright.clear();
    

    And now, there is nothing anymore in this model

    jList11.setModel(listModelFilterright);
    

    And now the second list uses that same, unique, empty object as its model.

    You need two discinct models. You want to remove all elements from the first one, and add them to the second one.