2

I have a JScrollPane that contains a JPanel of size 5000x5000 pixels. I want to limit the JScrollPane to only be able to show a subpart of this JPanel.

For example the rectangle defined by the two points (X,Y):

  • (500,500) (upper left corner)
  • (3000,3000) (lower right corner).

I have tried

 myJScrollPane.getHorizontalScrollBar().setMinimum(500); 

and

myJScrollPane.getHorizontalScrollBar().setMaximum(3000);

But it doesn't work. The setMinimum function only sets the position of the viewport on the scrollpane, setMaximum doesn't do anything.

alain.janinm
  • 19,951
  • 10
  • 65
  • 112
user1506145
  • 5,176
  • 11
  • 46
  • 75

1 Answers1

2

Change your JPanel instead to have size (2500, 2500) and render desired fragment of the image. Use translate() of the Graphics in paintComponent() for this.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • The thing is I am useing the JPanel as coordinate space to zoom in on an geometric object made of JLabels. I want to restrict the scrollbars so only the space containing the object is visible. I want to keep the coordinates of the object. – user1506145 Jul 06 '12 at 13:05