public class Test extends JFrame{
public Test(){
JPanel panel = new JPanel(){
{
this.setPreferredSize(new Dimension(2005,2005));
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
Rectangle2D rec = new Rectangle2D.Double(0,0,2000,2000);
g2.setPaint(Color.red);
g2.draw(rec);
}
};
Container con = this.getContentPane();
int v = JScrollPane.VERTICAL_SCROLLBAR_ALWAYS;
int h = JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS;
JScrollPane p = new JScrollPane(panel);
con.add(p,BorderLayout.CENTER);
}
public void show(){
this.setTitle("A big picture");
this.setSize(400,400);
super.show();
}
public static void main(String[] args){
new Test().show();
}
}