# Set a item of a JList with path

**URL:** https://discourse.processing.org/t/set-a-item-of-a-jlist-with-path/3939
**Category:** Coding Questions
**Created:** [September 28, 2018, 4:58pm UTC](https://discourse.processing.org/t/set-a-item-of-a-jlist-with-path/3939 "2018-09-28T16:58:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vjjv](https://avatars.discourse-cdn.com/v4/letter/v/df705f/32.png) [@vjjv](https://discourse.processing.org/u/vjjv)
#### Post date: [September 28, 2018, 4:58pm UTC](https://discourse.processing.org/t/set-a-item-of-a-jlist-with-path/3939/1 "2018-09-28T16:58:49Z")

</div>

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

```auto

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

```

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

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [September 29, 2018, 4:53pm UTC](https://discourse.processing.org/t/set-a-item-of-a-jlist-with-path/3939/2 "2018-09-29T16:53:28Z")

</div>

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](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-](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](https://processing.org/reference/HashMap.html)

---

<div class="post-metadata">

### Author: ![vjjv](https://avatars.discourse-cdn.com/v4/letter/v/df705f/32.png) [@vjjv](https://discourse.processing.org/u/vjjv)
#### Post date: [September 29, 2018, 4:55pm UTC](https://discourse.processing.org/t/set-a-item-of-a-jlist-with-path/3939/3 "2018-09-29T16:55:19Z")

</div>

Thanks. yes, is exactly what i need!
