JList item rename

A

a

Hi,
In Windows environment, to rename a file, the user can just select the name
of the icon displayed on the window explorer, then click on the name. The
file name field will become a text box and the user can rename the file
there.
I use JList and my own ListModel to show the data.
I would like to modify the data displayed on the JList.
How can I have the similar function for rename the file as the windows
explorer?
Thanks a lot
 
Z

zero

a said:
Hi,
In Windows environment, to rename a file, the user can just select the
name of the icon displayed on the window explorer, then click on the
name. The file name field will become a text box and the user can
rename the file there.
I use JList and my own ListModel to show the data.
I would like to modify the data displayed on the JList.
How can I have the similar function for rename the file as the windows
explorer?
Thanks a lot


Unfortunately there is no such thing as a list editor. Still, you have
several options here:

- rethink your GUI and use a JTable (eg with one column) or a JTree to
allow users to edit the nodes
- subclass JList to create your own editable list (you can use the JTable
or JTree source for ideas)
- add a popup menu to the JList, which allows you to edit the currently
selected item
- ...


An example using a one-column JTable:
http://www.esus.com/javaindex/j2se/jdk1.2/javaxswing/atomiccontrols/jlist
/jlisteditable.html

An example subclassing JList:
http://www.jroller.com/page/santhosh/20050607


The second example looks very good indeed. I haven't tested or examined
it thoroughly, but it looks very promising. And since Santhosh Kumar did
all the hard work for you, it should be easy to implement.
 
A

a

I have subclass JList and I have a popup menu for my JList, how this allows
me to edit the selected item?
Thanks
 
Z

zero

a said:
I have subclass JList and I have a popup menu for my JList, how this
allows me to edit the selected item?
Thanks

Did you look at the examples? The second example clearly shows how to
create an editable list. You can even run it using webstart:

http://www.jroller.com/resources/s/santhosh/EditableJList.jnlp

If you want to use a popup menu, just make it create a separate JFrame
that will let you enter new info, and then substitute that in the list.

But the easiest is just to take Santhosh Kumar's code. You can copy this
into a file, create a GUI that shows a JListMutable, compile, and you're
done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top