JPanel (@NotNull JComponent localsPanelComponent) { var top = createTopPanel(); if (top == null) { return super.createMainPanel(localsPanelComponent); } var layout = localsPanelComponent.getLayout(); boolean canAddComponentToTheRightOfToolbar = layout instanceof BorderLayout; if (canAddComponentToTheRightOfToolbar) { var panel = new BorderLayoutPanel() .addToCenter(((BorderLayout)layout).getLayoutComponent(BorderLayout.CENTER)) .addToTop(top); localsPanelComponent.add(panel, BorderLayout.CENTER); return super.createMainPanel(localsPanelComponent); } else { return new BorderLayoutPanel() .addToCenter(localsPanelComponent) .addToTop(top); } }