List of usage examples for javax.swing JPanel setAutoscrolls
@BeanProperty(bound = false, expert = true, description = "Determines if this component automatically scrolls its contents when dragged.") public void setAutoscrolls(boolean autoscrolls)
autoscrolls
property. From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(Main.class.getSimpleName()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BufferedImage bi = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(new ImageIcon(bi)); panel.add(label);/* ww w .ja va 2s . c o m*/ MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); ((JPanel) e.getSource()).scrollRectToVisible(r); } }; panel.addMouseMotionListener(doScrollRectToVisible); panel.setAutoscrolls(true); f.add(new JScrollPane(panel)); f.pack(); f.setSize(f.getWidth() / 2, f.getHeight() / 2); f.setVisible(true); }