Removing Object WIth Right Click
I have a JList comprised of People object. What I want to do is when the userrightclicks on one of the People objects an option comes up (in menu form or something) that says remove. Upon clicking remove, I want the person object removed from the JList.
Any suggestions on how to implement this?
Thank you.
You might want to check out the article http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html
Since the People in the list will change, you need to implement a ListModel as described in the section "Lists with Dynamic Contents".
Although right click handling is not dealt with, there is a section on "Double-Click Handling" which you could adapt for your needs. As well as using code like this to remove a Person from the list, you may want to update the current selection (if any) to reflect the change.
(The Swing forum is the best place to ask about JList usage.)
[Edit] I've just noticed that you want the remove action to be triggered by a popup menu item. Have a read of how such menus are used in Sun's Tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html