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 comments
Avatar
Vassiliy Kudryashov
Comment actions Permalink

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);
  }
1
Comment actions Permalink

@...

Very helpful answer. Thanks.

0

Please sign in to leave a comment.