Trying to create a remove button which removes items from a list

前端 未结 1 1659
南方客
南方客 2021-01-25 23:21

I am trying to make a remove button which will remove an item from \'order_List\'. The button that I have made \'removeButton\' removes only one item from the list and after tha

相关标签:
1条回答
  • 2021-01-25 23:58
    int selectionNumber = meal_List.getSelectedIndex();
    

    You get the selected index from the "meal_List".

    listOrder.removeElementAt(selectionNumber);
    

    But you try to delete the item from the "listOrder".

    Be consistent and use the same JList for both statements.

    Also, be consistent with naming. Why are you using an "_" in one of the JList names? Variable names should NOT contain an underscore. Check out Java conventions for some basics.

    0 讨论(0)
提交回复
热议问题