Permalink
Browse files

Merge pull request #71 from LordQuackstar/GUImaster

Allow GUI Traces to Autoscroll when at bottom
  • Loading branch information...
2 parents 2fd71bc + 1b078ef commit af274f56fc2e26ad5420af33357780e8c736ee04 @taconaut taconaut committed Aug 2, 2012
Showing with 19 additions and 4 deletions.
  1. +2 −2 src/main/java/net/pms/newgui/LooksFrame.java
  2. +17 −2 src/main/java/net/pms/newgui/TracesTab.java
@@ -387,8 +387,8 @@ public void quit() {
}
@Override
- public void append(String msg) {
- tt.getList().append(msg);
+ public void append(final String msg) {
+ tt.append(msg);
}
@Override
@@ -38,6 +38,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
+import javax.swing.text.DefaultCaret;
public class TracesTab {
private static final Logger logger = LoggerFactory.getLogger(TracesTab.class);
@@ -71,6 +72,7 @@ public void mouseReleased(MouseEvent e) {
}
}
private JTextArea jList;
+ protected JScrollPane jListPane;
TracesTab(PmsConfiguration configuration) {
this.configuration = configuration;
@@ -79,6 +81,19 @@ public void mouseReleased(MouseEvent e) {
public JTextArea getList() {
return jList;
}
+
+ public void append(String msg) {
+ getList().append(msg);
+ final JScrollBar vbar = jListPane.getVerticalScrollBar();
+ // if scroll bar already was at the bottom we schedule
+ // a new scroll event to again scroll to the bottom
+ if (vbar.getMaximum() == vbar.getValue() + vbar.getVisibleAmount())
+ EventQueue.invokeLater (new Runnable() {
+ public void run () {
+ vbar.setValue (vbar.getMaximum ());
+ }
+ });
+ }
public JComponent build() {
// Apply the orientation for the locale
@@ -115,8 +130,8 @@ public void actionPerformed(ActionEvent e) {
popup,
jList));
- JScrollPane pane = new JScrollPane(jList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- builder.add(pane, cc.xyw(1, 1, 2));
+ jListPane = new JScrollPane(jList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ builder.add(jListPane, cc.xyw(1, 1, 2));
// Add buttons opening log files
JPanel pLogFileButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));

0 comments on commit af274f5

Please sign in to comment.