I have defined a DirectoryListModel
class that extends the AbstractListModel
class from the Java Api.
Internally, I have a list of File
objects. I have defined the getElementAt(int index)
method as:
@Override
public Object getElementAt(int index) {
return directoryElements.get(index)
}
The problem is that when I try to run my JList with my DirectoryListModel
, it is going to show up the full paths of files instead of just the filenames. I could change this code to:
@Override
public Object getElementAt(int index) {
return directoryElements.get(index).getName();
}
and it'd work wonders, but the problem is that in the onclick event I'll want to have the File objects so I can do some checking with them (check if they're directories, etc).
If I make getElementAt()
return a String, I'm losing that possibility, thus I'd like to konw if there is a way I can format my File objects before the JList shows them in my window or if is there any simple and elegant way of doing this.
Thanks