I'm creating a simple project using hibernate. I know how to display records on JTable
as well as JList
but I don't know how can I display records from the JComboBox
. Anyway here are my code and guide me on displaying database record to the JComboBox
?
I don't have any error or anything but it only show one record and that is the last record I know it is on the loop, but can't still figure out how to display all record. So here are my code.
Variables:
private Object[] loadName;
Methods on Loading and retrieving data:
public Object[] LoadSupplier(){
b = a.openSession();
b.beginTransaction();
Query query = b.createQuery("FROM Supplier");
@SuppressWarnings("unchecked")
ArrayList<Supplier> load = (ArrayList<Supplier>) query.list();
b.getTransaction().commit();
b.close();
for(Supplier supply : load){
loadName = new Object[]{supply.getSupplierName()};
}
return loadName;
}
And for showing it to the database:
comboCategory = new JComboBox(LoadSupplier());
What I did is I call the method directly by putting it as the JComboBox
value :)
Tell me if I'm doing it right. And what is the best way on achieving the desired output?