package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public final class MainPanel extends JPanel {
    private MainPanel() {
        super(new BorderLayout());
        JPanel gp = new GridPanel();
        for (int i = 0; i < GridPanel.cols * GridPanel.rows; i++) {
            gp.add(i % 2 == 0 ? new JButton("aa" + i) : new JScrollPane(new JTree()));
        }
        JScrollPane scrollPane = new JScrollPane(gp);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
//         scrollPane.getVerticalScrollBar().setEnabled(false);
//         scrollPane.getHorizontalScrollBar().setEnabled(false);
//         scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension());
//         scrollPane.getHorizontalScrollBar().setPreferredSize(new Dimension());
        JPanel p = new JPanel();
        p.add(scrollPane);
        add(p);
        add(new JButton(new ScrollAction("right",  scrollPane, new Point(1,  0))), BorderLayout.EAST);
        add(new JButton(new ScrollAction("left",   scrollPane, new Point(-1, 0))), BorderLayout.WEST);
        add(new JButton(new ScrollAction("bottom", scrollPane, new Point(0,  1))), BorderLayout.SOUTH);
        add(new JButton(new ScrollAction("top",    scrollPane, new Point(0, -1))), BorderLayout.NORTH);
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.setSize(320, 240);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class GridPanel extends JPanel implements Scrollable {
    public static int cols = 3;
    public static int rows = 4;
    public static Dimension size = new Dimension(160 * cols, 120 * rows);
    protected GridPanel() {
        super(new GridLayout(rows, cols, 0, 0));
        //putClientProperty("JScrollBar.fastWheelScrolling", Boolean.FALSE);
    }
    @Override public Dimension getPreferredScrollableViewportSize() {
        Dimension d = getPreferredSize();
        return new Dimension(d.width / cols, d.height / rows);
    }
    @Override public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
        return orientation == SwingConstants.HORIZONTAL ? visibleRect.width : visibleRect.height;
    }
    @Override public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
        return orientation == SwingConstants.HORIZONTAL ? visibleRect.width : visibleRect.height;
    }
    @Override public boolean getScrollableTracksViewportWidth() {
        return false;
    }
    @Override public boolean getScrollableTracksViewportHeight() {
        return false;
    }
    @Override public Dimension getPreferredSize() {
        return size;
    }
}

class ScrollAction extends AbstractAction {
    protected static final double SIZE = 100d;
    protected final Point vec;
    protected final JScrollPane scrollPane;
    protected final Timer scroller = new Timer(5, null);
    protected transient ActionListener listener;
    protected int count;

    protected ScrollAction(String name, JScrollPane scrollPane, Point vec) {
        super(name);
        this.scrollPane = scrollPane;
        this.vec = vec;
    }
    @Override public void actionPerformed(ActionEvent e) {
        start();
    }
    protected void start() {
        if (scroller.isRunning()) {
            return;
        }
        JViewport vport = scrollPane.getViewport();
        JComponent v = (JComponent) vport.getView();
        int w  = vport.getWidth();
        int h  = vport.getHeight();
        int sx = vport.getViewPosition().x;
        int sy = vport.getViewPosition().y;
        Rectangle rect = new Rectangle(w, h);
        scroller.removeActionListener(listener);
        count = (int) SIZE;
        listener = e -> {
            double a = easeInOut(--count / SIZE);
            int dx = (int) (w - a * w + .5);
            int dy = (int) (h - a * h + .5);
            if (count <= 0) {
                dx = w;
                dy = h;
                scroller.stop();
            }
            rect.setLocation(sx + vec.x * dx, sy + vec.y * dy);
            v.scrollRectToVisible(rect);
        };
        scroller.addActionListener(listener);
        scroller.start();
    }
    protected static double easeInOut(double t) {
        //range: 0.0 <= t <= 1.0
        boolean isFirstHalf = t < .5;
        if (isFirstHalf) {
            return .5 * pow3(t * 2d);
        } else {
            return .5 * (pow3(t * 2d - 2d) + 2d);
        }
    }
    protected static double pow3(double a) {
        //return Math.pow(a, 3d);
        return a * a * a;
    }
}

@@ -268,25 +268,28 @@
 ));%0A        
-J
+Grid
 Panel gp = n
@@ -297,24 +297,28 @@
 w GridPanel(
+4, 3
 );%0A        f
@@ -340,34 +340,20 @@
 i %3C 
-GridPanel.cols * GridPanel
+gp.cols * gp
 .row
@@ -1120,17 +1120,16 @@
 %22right%22,
- 
  scrollP
@@ -1221,18 +1221,16 @@
 (%22left%22,
-  
  scrollP
@@ -1349,17 +1349,16 @@
 Point(0,
- 
  1))), B
@@ -1424,19 +1424,16 @@
 n(%22top%22,
-   
  scrollP
@@ -2373,59 +2373,49 @@
 lic 
-static int cols = 3;%0A    public static int rows = 4
+final int rows;%0A    public final int cols
 ;%0A  
@@ -2423,22 +2423,21 @@
  public 
-static
+final
  Dimensi
@@ -2447,48 +2447,8 @@
 size
- = new Dimension(160 * cols, 120 * rows)
 ;%0A  
@@ -2465,24 +2465,42 @@
 d GridPanel(
+int rows, int cols
 ) %7B%0A        
@@ -2550,16 +2550,17 @@
       //
+ 
 putClien
@@ -2614,24 +2614,135 @@
 ean.FALSE);%0A
+        this.rows = rows;%0A        this.cols = cols;%0A        this.size = new Dimension(160 * cols, 120 * rows);%0A
     %7D%0A    @O
@@ -4374,17 +4374,16 @@
   int w 
- 
 = vport.
@@ -4408,17 +4408,16 @@
   int h 
- 
 = vport.
@@ -5185,16 +5185,17 @@
       //
+ 
 range: 0
@@ -5450,16 +5450,17 @@
       //
+ 
 return M

use public final int variable instead of public static int