Block entire swing ui except for one component - “dialog style”

前端 未结 4 1667
旧时难觅i
旧时难觅i 2021-01-23 20:19

[This question is in relation to this question]

Setting: I have this home-crafted \"editable label\" component which looks like a label, but when you cl

4条回答
  •  星月不相逢
    2021-01-23 21:01

    This is rough. There is no method in Swing to block all UI except for one component. This is something you will have to build out yourself. Here is the design approach I would use:

    • Build a EditableLabelListener interface defining the method editableStateChanged(EditableLabelEvent)

    • Create a EditableLabelEvent class which extends AWTEvent and adds an editableState property and an isEditable() boolean value.

    • Add methods to your custom component for addEditableLabelListener and removeEditableLabelListener

    • On each panel where you use your component, have your controller class (which may be your panel, depending on your design) implement EditableEventListener and register itself as a listener to the component.

    • When the event is fired, the controller class should check the isEditable method on the event, and enable or disable all other components on the panel as appropriate. When there are multiple editable label components on the same form, you can use the getSource method on the event to determine which one is being used so you can disable the others.

提交回复
热议问题