Example usage for javax.swing JPanel setAutoscrolls

List of usage examples for javax.swing JPanel setAutoscrolls

Introduction

In this page you can find the example usage for javax.swing JPanel setAutoscrolls.

Prototype

@BeanProperty(bound = false, expert = true, description = "Determines if this component automatically scrolls its contents when dragged.")
public void setAutoscrolls(boolean autoscrolls) 

Source Link

Document

Sets the autoscrolls property.

Usage

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);
}