JList CellEditor

I have implemented a nice JList with a renderer.  I want to have the user clcik on an entry and then edit the text.  Here is a snippet of my code:

    m_list.setVisibleRowCount(0);
    m_list.setLayoutOrientation( JList.HORIZONTAL_WRAP );
    m_list.setCellRenderer( m_cellRenderer );

The list is emulating a file selection screen like windows explorer.  Everything works great except i dont know how to edit the name of selected objects.  CellEditors seem to be for the other components like JTable - not JList.

any pointers appreciated.
Randy
LVL 3
randydAsked:
Who is Participating?
 
CEHJCommented:
>>it should be just like the explorer view

Do you mean Windows Explorer? If so, i've never seen any wrapping such as you describe
0
 
CEHJCommented:
Sorry - wrong link. I see you're looking for an editor, not a renderer - that's what confused me. JLists are not editable. Can you remember ever seeing a list-like widget that is?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
girionisCommented:
You might be able to do it if you get the list model and add a listener to it:

list.getListModel().addListDataListener(new ListDataListener{
              public void contentsChanged(ListDataEvent event)
              {
                   // stuff here
              }
});
0
 
CEHJCommented:
You can certainly kludge one - by popping up a window with an 'editor cell' in it then changing the list model, but this would certainly violate a core principle of GUI design
0
 
randydAuthor Commented:
-- Can you remember ever seeing a list-like widget that is?

Well - in all other respects, the list looks like an explorer window.  It switches between large icons, small icons, etc, (no thumbnails) it wraps correctly - paints nicely - but in explorer, you can edit the name of a folder inline - in the JList you can't

girionis - i have an event that tells me that the selected item should be edited - i guess i can pup up a dialog to do it - but it would feel better to have it inline - that's sorta what i'm hoping for.

0
 
girionisCommented:
If you are looking for something like the explorer folder in windows why not use a JTree?
0
 
randydAuthor Commented:
the JTree part is either on the left in a splitpane- or in the drop down part of a directory combo, but the main display area that contains folders and files is what i'm working on.

as a matter of fact, i just checked, the JFileChoose dialog has implemented a folder name edit in the list view...

(and pre-emptively no - i cant use that one - my stuff is all in a database not a file system...)
0
 
girionisCommented:
> the JTree part is either on the left in a splitpane- or in the drop
> down part of a directory combo, but the main display area that contains
> folders and files is what i'm working on.

So why do you need to have a JTree ad a JList? Is the JTree not enough?
0
 
randydAuthor Commented:
The JTree is different -

you cant switch to large icons, reorder the directory entries, switch to details view and sort on columns etc.

take a look a JFileChooser - thats a low-rent version of what i'm doing..
0
 
CEHJCommented:
>>as a matter of fact, i just checked, the JFileChoose dialog has implemented a folder name edit in the list view...

Yes, but that comes from peer functionality and is a special case for working with files and directories. I think you'd a custom gui for a db equivalent of that
0
 
girionisCommented:
randyd,

will it be a problem if you use a JComboBox instead? You can have editable entries in there and besides it is using a JList internally to represent the contents.
0
 
randydAuthor Commented:
girions - the JCombo is not appropriate.

i think the closest thing would be a JTable - i could put the renderers on there and editors also - but then i would need to manage all the row wrapping manually - that sounds like a pain.

0
 
girionisCommented:
I think the best work around is the one suggested by CEHJ. Have a popup window where the user can enter the new name node and then reload the whole tree model.
0
 
objectsCommented:
For an editable JList, use a single column JTable.
0
 
objectsCommented:
0
 
girionisCommented:
I'd say split points between CEHJ and objects.
0
 
randydAuthor Commented:
i've been hoping for something... these answers really don't get me where i wanted to go...

i however do appeciate the efforts of all.
0
 
objectsCommented:
> these answers really don't get me where i wanted to go...

Where is that?
A single column table is equivalent to an editable list, whats wrong with using it?
0
 
randydAuthor Commented:
i need the cells to wrap from left to right and top to bottom.

when i resize the frame, the contents should auto wrap - so that there is a vertical scrollbar only. (always)

it should be just like the explorer view - so far, i have a context menu with a properties option - i can edit the name in that dialog...

will the JTable wrap this way?  i just assumed it would not.

a possible layout would be

1  2  3  4
5  6

then the winow shrinks and the new layout might be:

1  2  3
4  5  6

or if smaller:

1  2
3  4
5  6
0
 
randydAuthor Commented:
yes windows explorer.

1. open explorer
2. select 'Tiles' display mode
3. drag the window to make it smaller (width)

the items reorganize - this is the behavior i want.
0
 
objectsCommented:
you could implement that with a table, though there would be a little bit of work involved to get it to work.
You'd need to use a table model that supported displaying a list of items in a specified of columns.
You'd then adjust the number of columns depending on the size of the component.
0
 
objectsCommented:
Interesting choice of comments to accept :)
0
 
CEHJCommented:
:-)

>>2. select 'Tiles' display mode

I don't have such an option in Win2K. Maybe this is an XP thing ...

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.