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

后端 未结 7 1168
野性不改
野性不改 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:36

    I still feel like there is something conceptually wrong here.

    I empathize, but it may help to consider that you don't have a simple JList observing a ListSelectionModel. Instead, you have a JList and some-other-control observing a hybrid selection model. In @Taisin's example, the hybrid is a CustomSelectionModel that extends DefaultListSelectionModel and allows silent changes. When compatible, it's also possible to share a model, as suggested in this question & answer and this SharedModelDemo from the tutorial.

    For reference, this thread cites the article Java SE Application Design With MVC: Issues With Application Design, which addresses the issue in more detail.

提交回复
热议问题