Solved

JList CellEditor

Posted on 2004-08-27
25
2,893 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb mdb examples 1 39
Java pass by reference 3 74
listing all the respondents to a twitter feed - Java 5 47
Which is best Image Resizing Web service 11 41
In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

738 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