Set a item of a JList with path

hello!
anybody knows how can i set a JList item (saving previosly in a JSON file) with the PATH and not with INDEX?

this is becouse my list are dinamic, and maybe when i save a selection (index 2, e.x), next when i want load index 2 is not my selection(becouse i add a new item o delete)…


 int indexfrag = shader.getInt("shaderpathF");
JList f;
 f.setSelectedIndex(indexfrag);

i need something like f.setSelectedString or path… this is possible?

It looks like you want to know about using the available methods of javax.swing.JList in Java 8 for Processing(Java) – is that right?

https://docs.oracle.com/javase/8/docs/api/javax/swing/JList.html#method.summary

You might be looking for .setSelectedValue()

https://docs.oracle.com/javase/8/docs/api/javax/swing/JList.html#setSelectedValue-java.lang.Object-boolean-

Without seeing more of your code / knowing more about what you are trying to do, I’m not sure that I understand your question. I can’t tell what type of object shader is (PShader?) or what you mean by PATH (filepath string?).

In general, if you have a set-by-index object that you want to set-by-string, one way is to create a Map (like a HashMap) and store the string as the key and the index as the value. Then you can f.setSelectedIndex(map.get(“mykeystring”));

https://processing.org/reference/HashMap.html

1 Like

Thanks. yes, is exactly what i need!