Best way to stop a JTree selection change from happening?

前端 未结 7 2174
傲寒
傲寒 2021-01-06 05:07

I have a dialog where each entry in a JTree has its corresponding options in a different panel, which is updated when the selection changes. If options for one of the entrie

7条回答
  •  一整个雨季
    2021-01-06 05:28

    Not sure it's best practice, but maybe you could put a FocusListener on the component(s) you want to validate... call your validation when the event is called and then consume then event if you don't want the focus to be moved because the validation fails?

    Later Edit:

    At least with java 8 (I didn't check earlier versions) this solution won't work, because the FocusEvent appears not to be a low-level event. Hence it cannot be consumed. See Method AWTEvent.consume()

提交回复
热议问题