Search code examples
javaswingjscrollpane

How to display four sides scrollbars on JScrollPane


I have JScrollPane that contains a panel like JScrollPane scrollWindow = new JScrollPane(window); I overrided getPreferredSize() to display the scrollBars on the right and the bottom when I drag a shape outside the screen, that's worked fine The problem is when I drag to the left or the top, no scrollbars shows.

Any suggestions ?


Solution

  • A JScrollPane doesn't have the concept of displaying scrollbars for negative values. All Swing components start at (0, 0) and increase in width and height.

    If you want to drag components to a negative position then you will to recalculate the position of all components to be translated by the negative value of the dragged component.