How to refresh Tool Window
Hi,
I'm having a GUI related problem with custom Tool Windows. I have this simple code:
private void createUIComponents() {
panel = new JPanel();
panel.add(new JLabel("hello"));
panel.setVisible(true);
}
This works, however, I want to change it when the actionPerformed is called of the same class. My actionPerformed looks like this:
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
JPanel newPanel = new JPanel();
newPanel.add(new JLabel("world"));
newPanel.revalidate();
newPanel.repaint();
newPanel.updateUI();
newPanel.setVisible(true);
panel = newPanel;
}
When I run this in the debugger, the actionPerformed runs, however the tool window doesn't update. I looked in toolWindow for some kind of refresh method but found none. Any help would be great.
Also please may someone tell me how to set text as code when posting on here, thanks.
Please sign in to leave a comment.
Yes, existing layout from UI Designer cannot be updated after panel creation.
You can replace `JPanel panel` with `com.intellij.ui.components.panels.Wrapper` and use `Wrapper.setContent(JComponent)` method.
Or just update panel content:
>Also please may someone tell me how to set text as code when posting on here, thanks.
There are "Paragraph Styles" button on the toolbar (you might need to use "Shift+Enter" to separate formatted text from the rest).
Thanks, I ran into some issues. Updating the panel content still leads to no changes and when replacing JPanel panel with the wrapper, the tool window doesn't initialize. I run into this error:
This is my createUIComponents(), where wrapper is defined as Wrapper wrapper;
Please, share complete code of toolwindow initialisation.
https://github.com/AlexsFabulousFlow/ToolWindowPanel
Trigger the change by right clicking in editor and selecting Say world.
The problem is currently, it wont work because the form expects a JPanel and receives a Wrapper. If you replace the ToolWindowClass with the following code to update the panel:
Then the window initializes, but it doesn't update.
Sorry for the late reply,
Mentioned repository is not available.
Was the issue resolved?
No problem, also sorry for the late reply :). The issue was resolved, I ended up using the intellij message bus which refreshes all the guis perfectly. It seems just changing the panel directly either doesn't work, or works with a delay. Thanks for the help.
Hi,
I'm having the same issue with a Tool Window that I need to refresh when adding additional fields after some event, but validate() and repaint() doesn't work. How could you fixed it with the message bus? Thanks!