Skip to content

Commit ad58bd7

Browse files
committed
SwingConsolePane: keep console pane at the bottom
If the console pane is scrolled to the bottom, and there is new output, let's keep it scrolled to the bottom, so that output can be easily tracked by the human eye. But if the scroll bar is _not_ at the bottom, let's leave it where it is, to avoid disrupting the user. This matches the behavior of most terminal applications. Closes #7.
1 parent 0cb660c commit ad58bd7

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/main/java/org/scijava/ui/swing/console/SwingConsolePane.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.scijava.ui.UIService;
5555
import org.scijava.ui.console.AbstractConsolePane;
5656
import org.scijava.ui.console.ConsolePane;
57+
import org.scijava.ui.swing.StaticSwingUtils;
5758

5859
/**
5960
* Swing implementation of {@link ConsolePane}.
@@ -97,12 +98,14 @@ public void setWindow(final Component window) {
9798
@Override
9899
public void append(final OutputEvent event) {
99100
if (consolePanel == null) initConsolePanel();
101+
final boolean atBottom = StaticSwingUtils.isScrolledToBottom(scrollPane);
100102
try {
101103
doc.insertString(doc.getLength(), event.getOutput(), getStyle(event));
102104
}
103105
catch (final BadLocationException exc) {
104106
throw new RuntimeException(exc);
105107
}
108+
if (atBottom) StaticSwingUtils.scrollToBottom(scrollPane);
106109
}
107110

108111
@Override

0 commit comments

Comments
 (0)