void () { JComponent mainPanelInEditor = editor.getComponent(); LayoutManager layout = mainPanelInEditor.getLayout(); if (layout instanceof BorderLayout borderLayout) { Component originalCentralComponent = borderLayout.getLayoutComponent(BorderLayout.CENTER); JBLayeredPane intermediatePane = new JBLayeredPane() { @Override public void doLayout() { final Component[] components = getComponents(); final Rectangle bounds = getBounds(); for (Component component : components) { if (component == myGlobalScrollBar) { int scrollBarWidth = myGlobalScrollBar.getPreferredSize().width; component.setBounds(bounds.width - scrollBarWidth, 0, scrollBarWidth, bounds.height); } else { component.setBounds(0, 0, bounds.width, bounds.height); } } } @Override public Dimension getPreferredSize() { return originalCentralComponent.getPreferredSize(); } }; intermediatePane.add(originalCentralComponent, JLayeredPane.DEFAULT_LAYER); intermediatePane.add(myGlobalScrollBar, JLayeredPane.PALETTE_LAYER); mainPanelInEditor.add(intermediatePane, BorderLayout.CENTER); } else { // layout instanceof BorderLayout == false LOG.info("[Large File Editor Subsystem] EditorModel.insertGlobalScrollBarIntoEditorComponent():" + " can't insert GlobalScrollBar in normal way."); myRootComponent = new JPanel(); myRootComponent.setLayout(new BorderLayout()); myRootComponent.add(editor.getComponent(), BorderLayout.CENTER); myRootComponent.add(myGlobalScrollBar, BorderLayout.EAST); } }