Search code examples
javaswingjframejdialog

JFrame with dynamic modality


I have two JFrames.

One is the "main" Frame in which the User normally works. The second Frame is most of the time only there to give a better view of the data. The user clicks different Objects in the main Frame and the second Frame updates its View accordingly. (I actually have multiple of these "View"-Frames)

However I want the user to be able to edit the Data he sees in the second Frame as well.

I thought I would give him an "Edit"-Button in which he can enter an "Edit"-Mode which will move the second Frame into focus and temporarily "deactivate" the main Frame. He can leave the "Edit"-Mode with a "Save"-Button, which will reset the behavior to normal. Hence the main Frame gets the focus again and isn't "blocked" anymore

As I understand it i am not able to change the modality of an existing Frame.

The only solution I see at the moment would be to dispose (hide?) the second Frame and open a similar looking modal JDialog when the users presses "Edit". After Saving the JDialog is simply disposed.

Does anyone have a better solution?


Solution

  • Ok, I found a way that works for me.

    I pass the main Frame instance to the second Frame and when the Edit-Button is pressed I setEnabled(false) on the main Frame.

    Likewise I setEnabled(true) when the Save-Button is pressed.