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); } }
private JScrollBar createScrollBar(int row) { JScrollBar scrollBar = new JScrollBar(); scrollBar.setMinimum(0); scrollBar.setVisibleAmount(1); scrollBar.setBlockIncrement(1); scrollBar.setOrientation(JScrollBar.HORIZONTAL); GridBagConstraints scrollBarContraints = new GridBagConstraints(); scrollBarContraints.fill = GridBagConstraints.HORIZONTAL; scrollBarContraints.weightx = 1.0; scrollBarContraints.gridx = 1; scrollBarContraints.gridy = row; super.add(scrollBar, scrollBarContraints); return scrollBar; }
private void initialize() { this.setSize(733, 515); this.setLayout(new BorderLayout()); if (getContent() != null) { content = getContent(); getJTextPane().setText(new String(content)); } settings = PropertiesUtils.deserializeProperties(getSettings()); applySettings(); JScrollBar sb = getJScrollPane().getVerticalScrollBar(); if (sb != null) { String val = settings.getProperty(PROPERTY_SCROLLBAR_VERT); if (val != null) { sb.setVisibleAmount(0); sb.setValue(sb.getMaximum()); sb.setValue(Integer.valueOf(val)); } } sb = getJScrollPane().getHorizontalScrollBar(); if (sb != null) { String val = settings.getProperty(PROPERTY_SCROLLBAR_HORIZ); if (val != null) { sb.setVisibleAmount(0); sb.setValue(sb.getMaximum()); sb.setValue(Integer.valueOf(val)); } } String caretPos = settings.getProperty(PROPERTY_CARET_POSITION); if (!Validator.isNullOrBlank(caretPos)) { try { getJTextPane().setCaretPosition(Integer.valueOf(caretPos)); } catch (IllegalArgumentException iae) { // ignore incorrect caret positioning } } getJTextPane().getDocument().addUndoableEditListener(new UndoRedoManager(jTextPane)); getJTextPane() .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { dataChanged(); } public void insertUpdate(DocumentEvent e) { dataChanged(); } public void removeUpdate(DocumentEvent e) { dataChanged(); } private void dataChanged() { if (getJTextPane().isEditable()) { contentChanged = true; } } }); this.add(getJScrollPane(), BorderLayout.CENTER); this.add(getJToolBar(), BorderLayout.SOUTH); }