List of usage examples for javax.swing JScrollBar getValueIsAdjusting
public boolean getValueIsAdjusting()
From source file:me.mayo.telnetkek.MainPanel.java
private void writeToConsoleImmediately(final ConsoleMessage message, final boolean isTelnetError) { SwingUtilities.invokeLater(() -> { if (isTelnetError && chkIgnoreErrors.isSelected()) { return; }/*from w ww .ja va 2s. com*/ final StyledDocument styledDocument = mainOutput.getStyledDocument(); int startLength = styledDocument.getLength(); try { styledDocument.insertString(styledDocument.getLength(), message.getMessage() + System.lineSeparator(), StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, message.getColor())); } catch (BadLocationException ex) { throw new RuntimeException(ex); } if (MainPanel.this.chkAutoScroll.isSelected() && MainPanel.this.mainOutput.getSelectedText() == null) { final JScrollBar vScroll = mainOutputScoll.getVerticalScrollBar(); if (!vScroll.getValueIsAdjusting()) { if (vScroll.getValue() + vScroll.getModel().getExtent() >= (vScroll.getMaximum() - 50)) { MainPanel.this.mainOutput.setCaretPosition(startLength); final Timer timer = new Timer(10, (ActionEvent ae) -> { vScroll.setValue(vScroll.getMaximum()); }); timer.setRepeats(false); timer.start(); } } } }); }