Solved

JList CellEditor

Posted on 2004-08-27
25
2,816 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:randyd
  • 7
  • 6
  • 6
  • +1
25 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11916290
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11916330
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
 
LVL 35

Expert Comment

by:girionis
ID: 11916390
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11916453
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
 
LVL 3

Author Comment

by:randyd
ID: 11916463
-- 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
 
LVL 35

Expert Comment

by:girionis
ID: 11916497
If you are looking for something like the explorer folder in windows why not use a JTree?
0
 
LVL 3

Author Comment

by:randyd
ID: 11916574
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
 
LVL 35

Expert Comment

by:girionis
ID: 11916622
> 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
 
LVL 3

Author Comment

by:randyd
ID: 11916649
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11916655
>>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
 
LVL 35

Expert Comment

by:girionis
ID: 11916741
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
 
LVL 3

Author Comment

by:randyd
ID: 11916877
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 35

Expert Comment

by:girionis
ID: 11916898
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
 
LVL 92

Expert Comment

by:objects
ID: 11918316
For an editable JList, use a single column JTable.
0
 
LVL 92

Expert Comment

by:objects
ID: 11918324
0
 
LVL 35

Expert Comment

by:girionis
ID: 12256671
I'd say split points between CEHJ and objects.
0
 
LVL 3

Author Comment

by:randyd
ID: 12258392
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
 
LVL 92

Expert Comment

by:objects
ID: 12268168
> 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
 
LVL 3

Author Comment

by:randyd
ID: 12268949
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 60 total points
ID: 12270633
>>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
 
LVL 3

Author Comment

by:randyd
ID: 12273376
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
 
LVL 92

Assisted Solution

by:objects
objects earned 65 total points
ID: 12273412
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
 
LVL 92

Expert Comment

by:objects
ID: 12273489
Interesting choice of comments to accept :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12274810
:-)

>>2. select 'Tiles' display mode

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

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 79
allStar challenge 1 43
wordlen challenge 3 49
wordcount challenge 11 78
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now