I'm trying to create a screen that will allow me to scroll to different areas of the JPanel. i.e. I want a JPanel for drawing on which has a bigger size than the JFrame it is in, I am trying to use JScrollPane to view the different areas of the JPanel.
JFrame mainFrame = new JFrame("My Frame");
mainFrame.setSize(700, 700);
clickScreen = new ClickPanel();
clickScreen.setPreferredSize(new Dimension(2000, 2000));
JScrollPane scrollArea = new JScrollPane(clickScreen,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
mainFrame.getContentPane().add(scrollArea, BorderLayout.CENTER);
Where ClickPanel is a class I created which extends JPanel and is used for drawing.
My problem is: when I scroll using the scroll bars the view point moves, but the drawing from my paintComponent says in the same place. I want to be able to scroll to a new area below it so that I can draw there.