purefan
07-29-2006, 02:11 AM
Hello guys,
Im having some troubles using a JList properly, I've made a class Archivo, this is spanish for "File". This class has an attribute to set it to "Audio" or "Video". The point of the project is to make a "playlist manager", to be able to have several playlists and just add some files to it, so im trying to display a JList of the available files (which are all in a collection), then let the user choose one and decide whether to delete it or add it to a playlist, at this point I am trying to delete it.
Here is how I am declaring the JList:
// a String[] to store the toString from the ArrayList
String[] archivos = new String[listaArchivos.getSize()];
// Store the toStrings
for (int i = 0; i < listaArchivos.getSize(); i++) {
archivos[i] = listaArchivos.get(i).toString();
}
final JList coleccion = new JList(archivos);
So I am creating the JList from strings.
Then I am calling a function to actually delete the item selected:
if (listaArchivos.eliminarArchivo(coleccion.getSelectedValue())) {
// show success!
}
And here is the eliminarArchivo (spanish for deleteFile):
public boolean eliminarArchivo(Object eliminar) {
if (eliminar.getClass() == Archivo.class) {
for (int i = 0; i < this.size; i++) {
Archivo Aeliminar = (Archivo) eliminar;
Archivo comparar = (Archivo) listaArchivos.get(i);
if (Aeliminar.archivoID == comparar.archivoID) {
listaArchivos.remove(i);
return true;
}// if
}// for
return false;
}// if
return false;
}
The problem is that it is not working...it always returns there is nothing to delete...and I am not sure how should I handle the return of the JList, I mean, I know it returns "Object" but thats...well too ambiguous for me to know what to do, being made out of strings I tried to cast it into a string and didnt work...
So any clue or comment you might have please let me know! It will be much appreciated :smile:
I have attached the .java in case you want to take a full look
Im having some troubles using a JList properly, I've made a class Archivo, this is spanish for "File". This class has an attribute to set it to "Audio" or "Video". The point of the project is to make a "playlist manager", to be able to have several playlists and just add some files to it, so im trying to display a JList of the available files (which are all in a collection), then let the user choose one and decide whether to delete it or add it to a playlist, at this point I am trying to delete it.
Here is how I am declaring the JList:
// a String[] to store the toString from the ArrayList
String[] archivos = new String[listaArchivos.getSize()];
// Store the toStrings
for (int i = 0; i < listaArchivos.getSize(); i++) {
archivos[i] = listaArchivos.get(i).toString();
}
final JList coleccion = new JList(archivos);
So I am creating the JList from strings.
Then I am calling a function to actually delete the item selected:
if (listaArchivos.eliminarArchivo(coleccion.getSelectedValue())) {
// show success!
}
And here is the eliminarArchivo (spanish for deleteFile):
public boolean eliminarArchivo(Object eliminar) {
if (eliminar.getClass() == Archivo.class) {
for (int i = 0; i < this.size; i++) {
Archivo Aeliminar = (Archivo) eliminar;
Archivo comparar = (Archivo) listaArchivos.get(i);
if (Aeliminar.archivoID == comparar.archivoID) {
listaArchivos.remove(i);
return true;
}// if
}// for
return false;
}// if
return false;
}
The problem is that it is not working...it always returns there is nothing to delete...and I am not sure how should I handle the return of the JList, I mean, I know it returns "Object" but thats...well too ambiguous for me to know what to do, being made out of strings I tried to cast it into a string and didnt work...
So any clue or comment you might have please let me know! It will be much appreciated :smile:
I have attached the .java in case you want to take a full look