0

I`m getting this error:

java.util.vector cannot be cast to javax.collections.observablelist

When trying to populate TableView with List

this is my code error occurs on last line

try {
   emf = Persistence.createEntityManagerFactory("shopPu");
   em = emf.createEntityManager();
   List<Products> proList = em.createQuery("select p from Products p").getResultList();
   tableView.setItems((ObservableList<Products>)proList);
} catch (Exception e) {
   JOptionPane.showMessageDialog(null, e.getMessage());
} 

How i can bind List to my table or what is correct way to convert List to ObservableList?

athspk
  • 6,722
  • 7
  • 37
  • 51
user525717
  • 1,612
  • 5
  • 28
  • 40

1 Answers1

1

Use FXCollections to create an ObservableList.

ObservableList<E> observableList = FXCollections.observableList(list);
Jeffrey
  • 44,417
  • 8
  • 90
  • 141
  • Thank i set items but my dataTable does not showing data. Debugger shows that observableList contains 3 rows. Do i need any command to display after setItems? – user525717 Sep 03 '12 at 21:01
  • @user525717 You should probably ask another question with the relevant code to your problem. – Jeffrey Sep 03 '12 at 21:04
  • please help me here http://stackoverflow.com/questions/12259748/javafx-2-x-tableview-binding-columns – user525717 Sep 04 '12 at 14:59