Skip to content

Instantly share code, notes, and snippets.

@eirikbakke
Created January 14, 2016 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikbakke/09a090ab8052d38c8c87 to your computer and use it in GitHub Desktop.
Save eirikbakke/09a090ab8052d38c8c87 to your computer and use it in GitHub Desktop.
package com.sieuferd.uiutil;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import javax.swing.*;
public final class ScrollpaneTrackpadJitterBugExhibit extends JFrame {
private static final class ViewportPanel extends JPanel implements Scrollable {
public ViewportPanel() {
setLayout(new java.awt.GridLayout(2, 0, 0, 800));
//topLabel.setVerticalAlignment(SwingConstants.TOP);
add(new JLabel("Top of Viewport"));
//bottomLabel.setVerticalAlignment(SwingConstants.BOTTOM);
JLabel bottomLabel = new JLabel(
"<html>Line 1<br>Line 2<br>Line 3<br>Line 4<br>Line 5<br>Line 6<br>Bottom of Viewport</html>");
bottomLabel.setFont(new Font("Dialog", Font.PLAIN, 18));
add(bottomLabel);
}
@Override
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 30;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 30;
}
@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}
@Override
public boolean getScrollableTracksViewportHeight() {
return false;
}
}
public ScrollpaneTrackpadJitterBugExhibit() {
JScrollPane scrollPane = new JScrollPane(new ViewportPanel());
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER);
pack();
setSize(300, 400);
}
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ScrollpaneTrackpadJitterBugExhibit().setVisible(true);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment