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.

[334 byte] By [java4life87a] at [2007-11-27 11:59:24]
# 1

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

pbrockway2a at 2007-7-29 19:25:26 > top of Java-index,Java Essentials,Java Programming...
# 2

Sorry. Thought I was on the swing forums. I reposted it there.

java4life87a at 2007-7-29 19:25:26 > top of Java-index,Java Essentials,Java Programming...
# 3

> Sorry. Thought I was on the swing forums. I reposted it there.

No problem.

Reply here: http://forum.java.sun.com/thread.jspa?threadID=5199967&tstart=0

pbrockway2a at 2007-7-29 19:25:26 > top of Java-index,Java Essentials,Java Programming...