static JPanel scrollable_trackWidth(final Component component) { class P extends SingleComponentPanel implements Scrollable { *() { super(component); } public Dimension getPreferredScrollableViewportSize() { ret getPreferredSize(); } public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { return 20; } public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { ret (direction == SwingConstants.HORIZONTAL ? visibleRect.width : visibleRect.height)*5/6; } public bool getScrollableTracksViewportWidth() { true; } public boolean getScrollableTracksViewportHeight() { false; } } ret swing(func -> P { new P }); }