ToolWindows: main focus component, and resizing

Question 1

I noticed that when I open my ToolWindow, it focuses on the first focusable component of the JPanel that it contains.
Is there a way to control which JComponent gets the focus?
My JPanel has a dropdown select, and then a text field. I want the text field to be the one that gets focused.

Question 2

Regarding resizing my ToolWindow which is on the right-side of the IDE, for some reason:

  • When enlarging it, it appropriately gets my JPanel and its content to expand and take up more space
  • But when shrinking it, the JPanel doesn’t appear to become smaller: instead all components get their right-side cropped

Any ideas what might be causing this?

  1. com.intellij.ui.content.Content#setPreferredFocusableComponent
  2. What else would you expect?
1 Like

This worked great, thanks!

The content expands properly when the toolwindow grows in size.
I’d expect the content to shrink back down properly when the toolwindow reduces in size.

AFAIU that would depend on the LayoutManager and its settings for your main panel.