title: Display HashSet in a JList and real-time item update
body: <p>I'd like to display the content of a <a href="http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html" rel="nofollow">HashSet</a> in a <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JList.html" rel="nofollow">JList</a>. I achieved this by the following statement:</p>
  
  <pre><code>JList list = new JList(hashset.toArray());
  </code></pre>
  
  <p>Now, I'd like <code>list</code> to reflect the changes in <code>hashset</code>. I could do this by calling <code>setListData()</code> when the elements in <code>hashset</code> are changed, as below:</p>
  
  <pre><code>list.setListData(hashset.toArray());
  </code></pre>
  
  <p>This does not seem to be a proper way to do it. As I understood from the <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/list.html" rel="nofollow">tutorial</a>, I need to extend/implement a <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/ListModel.html" rel="nofollow">ListModel</a>. Please provide an appropriate example of overloading ListModel, if it is applicable to my intentions. Otherwise, kindly suggest a better approach to this.</p>
  
  <p>Thanks in advance.</p>