title: Convert ArrayList to Observable List for JavaFX program?
body: <p>I am a semi-beginner Java programmer, learning Java FX from a variety of sources.  In my program, I would like to create a ComboBox, and populate the choices with the toString() output of a series of objects from an ArrayList.  Here, pizza toppings are defined as an object.  They are created and stored in a PizzaMgr object, basically a glorified wrapper for an ArrayList:</p>
  
  <pre><code>public class Topping{
  
    private String name;
  
    public Topping(String a){
      this.name=a;
    }
    public String toString(){
      return this.name;
    }
  }
  
  //=================================================
  
  import java.util.ArrayList;
  
  public class PizzaMgr{
  
    private ArrayList&lt;Topping&gt; OrderedToppings;
  
    public PizzaMgr(){
        OrderedToppings = new ArrayList&lt;Topping&gt;();
        OrderedToppings.add(new Topping("Pepperoni"));
        OrderedToppings.add(new Topping("Mushrooms"));
        OrderedToppings.add(new Topping("Onions"));
    }
  
    public ArrayList&lt;Topping&gt; getList(){
        return OrderedToppings;
    }
  }
  </code></pre>
  
  <p>So far, so good.  But the hitch I hit is when I want a ComboBox to list all of those items in the PizzaMgr's ArrayList.  Ideally, I'd like to use this ComboBox constructor:</p>
  
  <pre><code>ComboBox&lt;T&gt;(ObservableList&lt;T&gt; items)
  </code></pre>
  
  <p>The problem?  How to extract all the ArrayList items into an Observable List?  I've been reading up on Arraylists, Observable Lists, interfaces in general, but I can't figure out how to get this to work.  I've read that an ArrayList is a Collection, and Observable List can be an interface to a Collection, so I thought I was home free.  However, when I try to implement the ComboBox constructor:</p>
  
  <pre><code>import javafx.scene.control.*;
  
  public class Menu{
  
    public static void main(String[] args){
        PizzaMgr m = new PizzaMgr();
        ComboBox&lt;Topping&gt; topMenu = new ComboBox&lt;Topping&gt;(m.getList());
    }
  }
  </code></pre>
  
  <p>I get the compiler error:</p>
  
  <pre><code>Menu.java:18: error: incompatible types: ArrayList&lt;Topping&gt; cannot be converted to ObservableList&lt;Topping&gt;
              ComboBox&lt;Topping&gt; topMenu = new ComboBox&lt;Topping&gt;(m.getList());
                                                                         ^
  </code></pre>
  
  <p>So obviously my ArrayList isn't seen as an Observable List.</p>
  
  <p>What stumps me is: How can I present my ArrayList to the ComboBox constructor, making it seem like an Observable List?  Is it a syntax slight-of-hand?  Or do I have to convert the ArrayList into another data structure in advance?</p>
  
  <p>Many thanks,
  -RAO</p>