Skip to content
This repository
Browse code

Merge pull request #71 from LordQuackstar/GUImaster

Allow GUI Traces to Autoscroll when at bottom
  • Loading branch information...
commit af274f56fc2e26ad5420af33357780e8c736ee04 2 parents 2fd71bc + 1b078ef
Philippe taconaut authored
4 src/main/java/net/pms/newgui/LooksFrame.java
@@ -387,8 +387,8 @@ public void quit() {
387 387 }
388 388
389 389 @Override
390   - public void append(String msg) {
391   - tt.getList().append(msg);
  390 + public void append(final String msg) {
  391 + tt.append(msg);
392 392 }
393 393
394 394 @Override
19 src/main/java/net/pms/newgui/TracesTab.java
@@ -38,6 +38,7 @@
38 38 import java.io.IOException;
39 39 import java.util.HashMap;
40 40 import java.util.Locale;
  41 +import javax.swing.text.DefaultCaret;
41 42
42 43 public class TracesTab {
43 44 private static final Logger logger = LoggerFactory.getLogger(TracesTab.class);
@@ -71,6 +72,7 @@ public void mouseReleased(MouseEvent e) {
71 72 }
72 73 }
73 74 private JTextArea jList;
  75 + protected JScrollPane jListPane;
74 76
75 77 TracesTab(PmsConfiguration configuration) {
76 78 this.configuration = configuration;
@@ -79,6 +81,19 @@ public void mouseReleased(MouseEvent e) {
79 81 public JTextArea getList() {
80 82 return jList;
81 83 }
  84 +
  85 + public void append(String msg) {
  86 + getList().append(msg);
  87 + final JScrollBar vbar = jListPane.getVerticalScrollBar();
  88 + // if scroll bar already was at the bottom we schedule
  89 + // a new scroll event to again scroll to the bottom
  90 + if (vbar.getMaximum() == vbar.getValue() + vbar.getVisibleAmount())
  91 + EventQueue.invokeLater (new Runnable() {
  92 + public void run () {
  93 + vbar.setValue (vbar.getMaximum ());
  94 + }
  95 + });
  96 + }
82 97
83 98 public JComponent build() {
84 99 // Apply the orientation for the locale
@@ -115,8 +130,8 @@ public void actionPerformed(ActionEvent e) {
115 130 popup,
116 131 jList));
117 132
118   - JScrollPane pane = new JScrollPane(jList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
119   - builder.add(pane, cc.xyw(1, 1, 2));
  133 + jListPane = new JScrollPane(jList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  134 + builder.add(jListPane, cc.xyw(1, 1, 2));
120 135
121 136 // Add buttons opening log files
122 137 JPanel pLogFileButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));

0 comments on commit af274f5

Please sign in to comment.
Something went wrong with that request. Please try again.