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

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

    I always do like this:

        public class MyDialog extends JDialog {
            private boolean silentGUIChange = false;
    
        public void updateGUI {
            try {
                silenGUIChange = true;
    
                // DO GUI-Updates here:
                textField.setText("...");
                checkBox.setSelected (...);
    
            }
            finally {
                silentGUIChange = false;
            }
        }
    
        private void addListeners () {
            checkBox.addChangeListener (new ChangeListener () {
               public void stateChanged (ChangeEvent e) {
                  if (silentGUIChange)
                     return;
    
                  // update MODEL
                  model.setValue(checkBox.isSelected());
              }
             });
        }
    
    }
    

提交回复
热议问题