Reputation: 139
I have some JTextComponent
s with some CaretEvent
s. I need to disable all the components to prevent user interaction after a certain actions and when that actions are completed reenable those JTextComponent
s to allow the user to interact again with the GUI. Obviously when the user clicks on a JTextComponent
the caret listener performs it's actions and I want to prevent that.
I currently removed the CaretListener
s to prevent that and after my internal operations are completed I re-add those CaretListener
s.
Is there any other way to prevent that? Such removing the MouseEvent
s for those components and reassign that later?
Upvotes: 1
Views: 170
Reputation: 285401
One way to disable user interaction is to not allow the text component to receive the program's focus:
myTextComponent.setFocusable(false);
And then later when you want to re-allow interaction, make the same call with the obvious true
parameter:
myTextComponent.setFocusable(true);
Upvotes: 1