How to add window focus listener for a custom tool window?
I have a issue same as following one : "Adding focus listener for a custom tool window" https://intellij-support.jetbrains.com/hc/en-us/community/posts/206137619-Adding-Focus-listener-for-a-custom-tool-window- . where no solution found.
"I have a custom tool window which shows a table with some data. I need to refresh the window when the window gains focus, previously some other view was active. How can I add a focus listeners?"
I tried swing component listener method: SwingUtilities.windowForComponent().addWindowFocusListener(). but no window found by method SwingUtilities.windowForCompoent().
Thanks,
Yang
Please sign in to leave a comment.
Hello. Please try this code for your custom Tool Window:
new FocusWatcher(){
@Override
protected void focusedComponentChanged(Component focusedComponent, @Nullable AWTEvent cause) {
if (focusedComponent != null && SwingUtilities.isDescendingFrom(focusedComponent, toolWindow.getComponent())) {
//refresh table here
}
}
}.install(toolWindow.getComponent());
Thanks