How to dynamically set the width of the Tool Window?

Answered

I have tried toolWindow.getComponent().setSize(), toolWindow.getComponent().setPreferredSize(), as well as the component's parent but it won't change. I need to be able to dynamically set the size on start up, not just with the form.

2
2 comments
Avatar
Permanently deleted user

Hi, please try this code snippet:

  static void setToolWindowWidth(Project project, String toolWindowID, int desiredWidth) {
    ToolWindowManager instance = ToolWindowManager.getInstance(project);
    ToolWindowEx tw = (ToolWindowEx) instance.getToolWindow(toolWindowID);
    int width = tw.getComponent().getWidth();
    tw.stretchWidth(desiredWidth - width);
  }
3

@...

Very helpful answer. Thanks.

0

Please sign in to leave a comment.