I am trying to design a class of endless coordinate board with a grid. I have extended a JViewport
and it draws at initial position ok (inside JScrollPane
). How to tell scroll pane that there are some space to scroll in any direction?
The following does not help
JCoordinateViewport coordinate = new JCoordinateViewport();
coordinate.setBackground(Color.WHITE);
//coordinate.setPreferredSize(new Dimension(10000, 10000));
JScrollPane scroll = new JScrollPane();
//scroll.setViewportView(coordinate);
scroll.setViewport(coordinate);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.getVerticalScrollBar().setMinimum(-10000);
scroll.getVerticalScrollBar().setMaximum(+10000);
scroll.getHorizontalScrollBar().setMinimum(-10000);
scroll.getHorizontalScrollBar().setMaximum(+10000);
UPDATE
Does anybody knows how JScrollPane determines scroll ranges from it's viewport?
UPDATE2
I found, that scrollbars appear t work if maximums and minimums are set after setVisible
called.
But unfortunately, paintConponent
does not called upon scroll.
Why?
UPDATE3
Although scroll bars work, they don't change viewport position.
Why?