private void recalculateMaxValues() { myIdxLeft = widestEditor(myLeftEditors); final Editor leftEditor = myLeftEditors.get(myIdxLeft); final int wholeWidth = leftEditor.getContentComponent().getWidth(); final Rectangle va = leftEditor.getScrollingModel().getVisibleArea(); final int visibleLeft = leftEditor.xyToVisualPosition(new Point(va.width, 0)).column; myMaxColumnsLeft = (int) (visibleLeft * ((double) wholeWidth / va.getWidth())); myIdxRight = widestEditor(myRightEditors); final Editor rightEditor = myRightEditors.get(myIdxRight); final int wholeWidthRight = rightEditor.getContentComponent().getWidth(); final Rectangle vaRight = rightEditor.getScrollingModel().getVisibleArea(); final int visibleRight = rightEditor.xyToVisualPosition(new Point(va.width, 0)).column; myMaxColumnsRight = (int) (visibleRight * ((double) wholeWidthRight / vaRight.getWidth())); myByLeft = !(myMaxColumnsLeft <= visibleLeft); if (!myByLeft) { // check right editor if (myLeftScroll.getVisibleAmount() != visibleRight) { myLeftScroll.setVisibleAmount(visibleRight); } myLeftScroll.setMaximum(myMaxColumnsRight); } else { if (myLeftScroll.getVisibleAmount() != visibleLeft) { myLeftScroll.setVisibleAmount(visibleLeft); } myLeftScroll.setMaximum(myMaxColumnsLeft); } }
public void afterPanelsAdded() { myLeftScroll.setMinimum(0); myLeftScroll.setMaximum(myMaxColumnsLeft); myLeftScroll.addAdjustmentListener( new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { myInScrolling = true; final int scrollPosCorrected = myLeftScroll.getValue() + 1; if (myByLeft) { scrollMain(myLeftScroll.getValue(), myLeftModels); scrollOther(scrollPosCorrected, myMaxColumnsLeft, myMaxColumnsRight, myRightModels); } else { scrollMain(myLeftScroll.getValue(), myRightModels); scrollOther(scrollPosCorrected, myMaxColumnsRight, myMaxColumnsLeft, myLeftModels); } myInScrolling = false; } }); }