Is there something wrong with Swing's MVC implementation for JList?

后端 未结 7 1165
野性不改
野性不改 2020-12-11 16:08

Some time ago I asked this question. All solutions are workarounds.

Now this can\'t be. I feel that something is wrong here, but I can\'t tell if it is Swing\'s MVC

7条回答
  •  借酒劲吻你
    2020-12-11 16:28

    This is expected behaviour.

    From Model-View-Controller [Wikipedia]:

    In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.

    So, when you call setSelectedIndex on the JList, you are updating its model, which then notifies each ListSelectionListener. It wouldn't be MVC if you could "silently" update a model without letting anyone know.

提交回复
热议问题