0

I have created a jdialog which contains a combobox (see photo ).

The combobox contains items of Delivery class. The date you see in the photo is the value returns from Delivery.toString().

When i press OK, i need to return the Delivery object that is selected from the combobox, to the parent form.

billato
  • 13
  • 4

1 Answers1

0

You could use something along the lines of:

    public BillatoDialog extends JDialog(){
       private Delivery selectedDelivery; // Declare selectedDelivery variable

       String selectedDate = comboBox.getSelectedItem();    // Returns the current selected item.
       for (Delivery currentDelivery: deliveryList){        // Loop over a list with all the deliverys. 
          if (currentDelivery.toString()==selectedDate;){  // and break the for when match found.
          selectedDelivery = currentDelivery;          // assign it to selectedDelivery
          break;
          }
       }

      public Delivery getSelectedDelivery(){
         return selectedDelivery;
      }
}

And then in your JPanel

public BillatoPanel extends JPanel(){
   openBillatoDialog();
   getSelectedDelivery();
}
ManyQuestions
  • 1,069
  • 1
  • 16
  • 34
  • Please leave a message if this helped you. – ManyQuestions May 13 '14 at 19:21
  • Your code is nice. I can already get the Delivery object in the selectedDelivery object. My question is how i can return the selectedDelivery object to the parent form (the one that called the jdialog). – billato May 14 '14 at 05:44
  • I open the JDialog and when i click OK, i need to return to the parent form the Delivery object that is selected in the combobox. – billato May 14 '14 at 13:52
  • Also check out this post: http://stackoverflow.com/questions/4089311/how-can-i-return-a-value-from-a-jdialog-box-to-the-parent-jframe?rq=1 – ManyQuestions May 14 '14 at 14:14
  • You are correct. My problem is a bit different but its my fault. I didn't described it correctly. I am calling the JDialog from a jpanel... – billato May 14 '14 at 14:46
  • @billato If this answer helped you please accept it as an answer so others can see it is resolved. – ManyQuestions May 14 '14 at 14:51
  • Is there a way to return the object from the JDialog to a jpanel? – billato May 14 '14 at 15:01