void () { myPanel.setLayout(new BorderLayout()); myPanel.add(myHeaderPanel, BorderLayout.NORTH); myGutterComponent.setOpaque(true); myScrollPane.setViewportView(myEditorComponent); //myScrollPane.setBorder(null); myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); myScrollPane.setRowHeaderView(myGutterComponent); myScrollingModel.initListeners(); myEditorComponent.setTransferHandler(new MyTransferHandler()); myEditorComponent.setAutoscrolls(false); // we have our own auto-scrolling code JLayeredPane layeredPane = new PanelWithFloatingToolbar(); layeredPane.add(myScrollPane, JLayeredPane.DEFAULT_LAYER); UiNotifyConnector.doWhenFirstShown(myPanel, () -> { if (mayShowToolbar()) { layeredPane.add(new EditorFloatingToolbar(this), JLayeredPane.POPUP_LAYER); } }, getDisposable()); myPanel.add(layeredPane, BorderLayout.CENTER); myEditorComponent.addKeyListener(new KeyListener() { @Override public void keyPressed(@NotNull KeyEvent e) { if (EVENT_LOG.isDebugEnabled()) { EVENT_LOG.debug(e.toString()); } if (e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() <= KeyEvent.VK_Z) { myCharKeyPressed = true; } } @Override public void keyTyped(@NotNull KeyEvent event) { if (EVENT_LOG.isDebugEnabled()) { EVENT_LOG.debug(event.toString()); } myNeedToSelectPreviousChar = false; if (event.isConsumed()) { return; } if (processKeyTyped(event)) { event.consume(); } } @Override public void keyReleased(KeyEvent e) { if (EVENT_LOG.isDebugEnabled()) { EVENT_LOG.debug(e.toString()); } myCharKeyPressed = false; } }); myEditorComponent.addMouseListener(myMouseListener); myGutterComponent.addMouseListener(myMouseListener); myEditorComponent.addMouseMotionListener(myMouseMotionListener); myGutterComponent.addMouseMotionListener(myMouseMotionListener); myEditorComponent.addFocusListener(this); UiNotifyConnector.doWhenFirstShown(myEditorComponent, myGutterComponent::updateSizeOnShowNotify, getDisposable()); try { DropTarget dropTarget = myEditorComponent.getDropTarget(); if (dropTarget != null) { // might be null in headless environment dropTarget.addDropTargetListener(new DropTargetAdapter() { @Override public void drop(@NotNull DropTargetDropEvent e) { } @Override public void dragOver(@NotNull DropTargetDragEvent e) { Point location = e.getLocation(); final CaretImpl caret = getCaretModel().getCurrentCaret(); caret.moveToVisualPosition(getTargetPosition(location.x, location.y, true, caret)); getScrollingModel().scrollToCaret(ScrollType.RELATIVE); requestFocus(); } }); } } catch (TooManyListenersException e) { LOG.error(e); } // update area available for soft wrapping on the component shown/hidden myPanel.addHierarchyListener(e -> mySoftWrapModel.getApplianceManager().updateAvailableArea()); myPanel.addComponentListener(new ComponentAdapter() { @DirtyUI @Override public void componentResized(@NotNull ComponentEvent e) { myMarkupModel.recalcEditorDimensions(); myMarkupModel.repaint(); if (!isRightAligned()) return; updateCaretCursor(); myCaretCursor.repaint(); } }); }