I'm trying to use JScrollPanel, but very time i repaint it, it scrolls down and right. I want it to maintain position.

Both ScrollBars are enabled with JScrollPane.VERTICAL/HORIZONTAL_SCROLLBAR_ALWAYS. I am using removeAll() and add() for the panel inside the ScrollPane. When i use repaint(), ScrollBars are moving down and right. What should I do? Should i repaint ScrollPane or the panel inside of it? Thanks in advance. My code:

public static void openWindow() {
frame = new JFrame();
//...
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
scrollPane = new JScrollPane(panel,JScrollPane.VERTICAL_SCROLLBAR_A LWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//...
frame.add(scrollPane);
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setDefaultCloseOperation(WindowConstants.EXI T_ON_CLOSE);
frame.setUndecorated(true);
frame.setResizable(false);
frame.pack();
frame.setVisible(true);
GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame );
Window.repaintWindow();
}
public static void repaintWindow() {
panel.removeAll();
//adding new elements
panel.repaint();
}