hello all,
Can anybody tell me how to activate a scrollbar for a jpanel. I have drawn 15 rectangles using paint method.My code goes here..
Java Code:
//start of the class//
 super(new BorderLayout());
      Dimension d=new Dimension(800,800);
      drawpane.setBackground(Color.LIGHT_GRAY);//JPanel drawpane
      drawpane.setPreferredSize(d);
      JScrollPane scroller = new JScrollPane(drawpane,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      scroller.setBackground(Color.MAGENTA);      
      add(scroller, BorderLayout.CENTER);
         }
//drawing the rectangles//
    public class DrawingPane extends JPanel{   
   protected void paintComponent(Graphics g) {
    super.paintComponent(g);
       for(int i=0;i<15;i++)
    {
    g.setColor(Color.blue);
    g.drawRect(x, y, 100, 100);
    g.setColor(Color.red);
    g.drawString("hai "+i,x+50 ,y+50);
    g.setColor(Color.YELLOW);
    x1=x+100;
    y1=y+50;
    x2=x1+60;
    y2=y1;
    g.drawLine(x1,y1,x2 ,y2);
     x1=x2;
     y1=y2;
     x2=x1;
     y2=y1+60;
     g.drawLine(x1, y1, x2, y2);
    x+=100+10;
    y+=100+10;
    }
    }
Please anybody help me with the scroll bar problem.how and when to use repaint().I am new to swing and applets.:confused:.Help me.
Thanks in advance.
Regards,
Gnanaprakasam