My graphics paint area is too large and requires a scrollable function to increase the area that can be made visible. I am having trouble finding out how to do this.
I have tried add a JScrollPane but even when I am able to make it show up, it doesn't actually let me scroll through my drawing area. I already read the documentation on Custom Graphics but couldn't find anything about scroll bars. I am currently looking to see if I am able to somehow change the limits that the scroll bar has set (right now seems to be fixed to the size of the window) but was hoping I could get guidance.
public class Practice extends JPanel {
private String text;
Practice(){
text="Test";
}
Practice(String x){
text=x;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.BLACK);
//drawing a bunch of shapes and text
}
public static void main(String[] args) {
JFrame j = new JFrame("Test");
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setSize(500, 500);
JScrollPane scrollPane = new JScrollPane(new Practice("Test"));
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
j.add(scrollPane);
j.setVisible(true);
}
}