1

I have 2 views in my application in one of them (lets call it A) I can enter a value and add this to a List in the next view (lets call it B) when I launch this view everything is just fine when I add every item like this in my constructor

for (Rekening r : app.getRekeningen()) {
         rekeningList.addItem(r);
}

But when I add a new item in view A while view B is open it obviously doesn't update the JComboBox with the new value. My question is How can I achieve this?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Reshad
  • 2,570
  • 8
  • 45
  • 86

1 Answers1

2

You have a couple of options:

  • Create a reference to the listModel in B that you can update in A
  • A method on B that you can call from A that will take the new value as a parameter. Then add that item to the list model and possibly call repaint() on the view.
jzd
  • 23,473
  • 9
  • 54
  • 76
  • Thanks. I used the second for the input box in B but is it a best practice that views know each others presence? I assumed that it had to do anything with a kind of observable or anything. – Reshad Oct 24 '13 at 11:45
  • It is not bad practice for A to know about B. What becomes a problem is when A depends on B and B depends on A, that is called 'coupling'. – jzd Oct 24 '13 at 12:18