Following is my program i need to add scroll to jframe and I have paint method in it

package other;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.ScrollPane;
import java.awt.Stroke;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Line2D;

import javax.swing.*;


public class MainDrawCycle extends JPanel implements ActionListener 
{

    JButton button;
    JLabel label;
    JTextField textField;
    JScrollPane pane;
    JPanel panel;
    JFrame frame;
    Container c;
    static int val;
    int xa,ya,xb,yb,x1,y1;
    int xc,yc,xd,yd,xe,ye,xf,yf;
    int lsb=0,msb=7;
    char val1='A',val2='B';

//  public MainDrawCycle(JFrame f)
//  {       
//      pane=new //JScrollPane(f,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//      add(pane);
//  }
    public MainDrawCycle() 
    {

        setLayout(null);

        //frame=new JFrame();

//      panel=new JPanel();
//      pane=new //JScrollPane(panel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

        textField=new JTextField();
        label=new JLabel("Enter Clock value: ");
        button=new JButton("Ok");

        System.out.println("in const");
        label.setBounds(300,550,80,20);
        textField.setBounds(410,550,50,20);
        button.setBounds(480,550,70,20);

        //add(pane);
        add(button);
        add(textField);
        add(label);
        button.addActionListener(this);


    }



    public void paint(Graphics g) 
    {

        xa=50;ya=60;xb=100;yb=60;x1=100;y1=520;
        xc=100;yc=60;xd=100;yd=100;xe=100;ye=100;xf=150;yf=100;


        g.setColor(Color.black);
        g.drawLine(50,50,50,y1);  //Y axis
        //g.drawLine(20,500,x1,500);  //X axis
        g.drawString("CLK",xa-40 ,ya);
        g.drawString("DATA", xa-40, 300);
        g.drawString("["+msb+":"+lsb+"]", xa-40, 310);

        Graphics2D g2d = (Graphics2D)g;
        Stroke stroke=new BasicStroke(1f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_BEVEL,1f, new float[] {2f}, 0f);
        Stroke drawingStroke = new BasicStroke(2);

        for(int i=1;i<=val;i++)
        {
            g2d.setStroke(stroke);
            Line2D line = new Line2D.Double(xb,yb,xb,500);
            g2d.draw (line);
            Line2D line2 = new Line2D.Double(xf,yf-50,xf,500);
            g2d.draw (line2); 
            g2d.setStroke(drawingStroke);

            if(x1<xf)
            {
                x1=xf;
                g.setColor(Color.black);
                g.drawLine(20,500,x1,500);  //X axis
            }
            g.drawString("t "+i,xa+30,ya-10);

            g.setColor(Color.blue);
            g.drawLine(xa,ya,xb,yb);        //h1
            g.setColor(Color.blue);         
            g.drawLine(xc,yc,xd,yd);        //v1
            g.setColor(Color.blue);  
            g.drawLine(xe,ye,xf,yf);        //h2
            if(i%2==0)
            g.drawString("A"+val1,(xa+xf)/2, 300);
            else
            g.drawString("B"+val2,(xa+xf)/2 , 300);

            g.drawLine(xa, 300, (xa+xb)/2, 275);
            g.drawLine((xa+xb)/2, 275, (xd+xf)/2, 275);
            g.drawLine((xd+xf)/2, 275, xf, 300);
            g.drawLine((xa+xb)/2, 325, (xd+xf)/2, 325);
            g.drawLine(xa, 300, (xa+xb)/2, 325);
            g.drawLine((xd+xf)/2, 325, xf, 300);

            xa=xf;
            ya=ya;
            xb=xe+100;
            yb=yb;

            xc=xb;
            yc=yb;
            xd=xf+50;
            yd=yf;

            xe=xd;
            ye=yd;
            xf=xe+50;
            yf=yf;



        }


        {

        }
    }

    public static void main(String[] args) 
    {
        JFrame frame = new JFrame();
        JScrollPane pane=new JScrollPane(new MainDrawCycle(),JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        frame.getContentPane().add(pane);
//      new MainDrawCycle(frame);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(900,700);
        frame.setVisible(true);


    }

    @Override
    public void actionPerformed(ActionEvent e) 
    {

        if(e.getSource()==button)
        {
            val=Integer.parseInt(textField.getText());
            repaint();
        }

    }


}
  1. Post your code in CODE tags so we can read it.
  2. frame.getContentPane().add(pane); the getContentPane() hasn't been required since Java 1.5
  3. Never override paint(), override paintComponent instead.
  4. Because your custom JPanel has no components in it Swing doesn't know how big it is, and probably has its size as 0,0 So the scroll pane won't do much. You may do better by setting your panel's size to a suitable value

Thank u very much

but i cant get how to use "frame.getContentPane().add(pane)"

I have jdk 1.6 version.

You can simply use frame.add(pane);

I was trying but still it is not working ..

It only show me scroll bar on frame but not working

can you pl's run my code...
Thank you...

Sorry, I don't have time to run your code today. What exactly do you mean by "but not working"? Specify what you expected to see and what you actually saw.

I want to add scroll to jpanel which is on frame

Yes, you made that clear with your first post.

Yes i know that but still i didn't see the scroll bar on jframe...

What sizes did you set?

Yes i know that but still i didn't see the scroll bar on jframe...

there are three possible issues

- contents Size that you put ot the JScrollPane is lover than JViewPort View

- you nothing put to the JScrollPane

- change XXX_SCROLLBAR_AS_NEEDED to XXX_SCROLLBAR_AS_ALLWAYS

public static void main(String[] args)
{
JFrame frame = new JFrame();
JScrollPane pane=new JScrollPane(new MainDrawCycle(),JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
frame.getContentPane().add(pane);
// new MainDrawCycle(frame);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(900,700);
frame.setVisible(true);


this size i set

Again I post my program but still scroll bar didn't added

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.ScrollPane;
import java.awt.Stroke;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Line2D;
import javax.swing.*;

public class MainDrawCycle extends JPanel implements ActionListener,Runnable 
{

	JButton button;
	JLabel label;
	JTextField textField;
	JScrollPane pane;
	JPanel panel;
	JFrame frame;
	Container c;
	static int val;
	int xa,ya,xb,yb,x1,y1;
	int xc,yc,xd,yd,xe,ye,xf,yf;
	int lsb=0,msb=7;
	char val1='A',val2='B';
	Thread runner=null;
	public MainDrawCycle() 
	{
		setLayout(null);
		//setSize(600,600);
		setBackground(Color.green);
		textField=new JTextField();
		label=new JLabel("Enter Clock value: ");
		button=new JButton("Ok");

		System.out.println("in const");
		label.setBounds(280,550,120,20);
		textField.setBounds(410,550,50,20);
		button.setBounds(480,550,70,20);

		add(button);
		add(textField);
		add(label);
		button.addActionListener(this);


	}

	public void paintComponent(Graphics g) 
	{

		xa=50;ya=60;xb=100;yb=60;x1=100;y1=520;
		xc=100;yc=60;xd=100;yd=100;xe=100;ye=100;xf=150;yf=100;

		Font f=new Font("serif", Font.BOLD,15);
		
		g.setColor(Color.black);
		g.drawLine(50,50,50,y1);  			// Draw Y axis.
		g.drawString("CLK",xa-40 ,ya);
		g.drawString("DATA", xa-40, 300);
		g.drawString("["+msb+":"+lsb+"]", xa-40, 312);
		
		
		g.setFont(f);
		g.setColor(Color.red);
		g.drawString("Timing Analysis", 400, 12);


		Graphics2D g2d = (Graphics2D)g;
		Stroke stroke=new BasicStroke(1f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_BEVEL,1f, new float[] {2f}, 0f);
		Stroke drawingStroke = new BasicStroke(2);

		for(int i=1;i<=val;i++)
		{
			g2d.setColor(Color.black);
			g2d.setStroke(stroke);
			Line2D line = new Line2D.Double(xb,yb,xb,500);
			g2d.draw (line);
			Line2D line2 = new Line2D.Double(xf,yf-50,xf,500);
			g2d.draw (line2); 
			g2d.setStroke(drawingStroke);

			if(x1<xf)
			{
				x1=xf;
				g.setColor(Color.black);
				g.drawLine(20,500,x1,500);  //Draw X axis.
			}
			g.drawString("t "+i,xa+30,ya-10);

			g.setColor(Color.blue);
			g.drawLine(xa,ya,xb,yb);		//h1
			g.setColor(Color.blue);         
			g.drawLine(xc,yc,xd,yd);  		//v1
			g.setColor(Color.blue);  
			g.drawLine(xe,ye,xf,yf);     	//h2
			
			if(i%2==0)
				g.drawString(""+val1,(xa+xf)/2, 300);
			else
				g.drawString(""+val2,(xa+xf)/2 , 300);

			g.drawLine(xa, 300, (xa+xb)/2, 275);
			g.drawLine((xa+xb)/2, 275, (xd+xf)/2, 275);
			g.drawLine((xd+xf)/2, 275, xf, 300);
			g.drawLine((xa+xb)/2, 325, (xd+xf)/2, 325);
			g.drawLine(xa, 300, (xa+xb)/2, 325);
			g.drawLine((xd+xf)/2, 325, xf, 300);

			xa=xf;
			ya=ya;
			xb=xe+100;
			yb=yb;

			xc=xb;
			yc=yb;
			xd=xf+50;
			yd=yf;

			xe=xd;
			ye=yd;
			xf=xe+50;
			yf=yf;



		}

	}

	public static void main(String[] args) 
	{
		JFrame frame = new JFrame();
		JScrollPane pane=new JScrollPane(new MainDrawCycle(),JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		frame.getContentPane().add(pane);
		//		new MainDrawCycle(frame);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setExtendedState(frame.MAXIMIZED_BOTH);
		
		//frame.setSize(900,700);
		frame.setVisible(true);


	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{

		if(e.getSource()==button)
		{
			val=Integer.parseInt(textField.getText());
			repaint();
			
		}

	}

	@Override
	public void run() {
		
		
		// lower ThreadPriority
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

		// run a long while (true) this means in our case "always"
		while (true)
		{

		      // repaint the applet
		      repaint();

		      try
		      {
		            // Stop thread for 20 milliseconds
		            Thread.sleep (100);
		      }
		      catch (InterruptedException ex)
		      {
		            // do nothing
		      }

		      // set ThreadPriority to maximum value
		      Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

		} 
		
		
		// TODO Auto-generated method stub
//		while(runner!=null)
//			repaint();
//		try
//		{
//			Thread.sleep(100);
//		}catch(InterruptedException i)
//		{
//			System.out.println(i.getMessage());
//		}
				
	}
public void start()
	{
		if(runner==null)
		{
			runner=new Thread(this);
			runner.start();
		}
	}	

}

Again I post my program but still scroll bar didn't added

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.ScrollPane;
import java.awt.Stroke;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Line2D;
import javax.swing.*;

public class MainDrawCycle extends JPanel implements ActionListener,Runnable 
{

	JButton button;
	JLabel label;
	JTextField textField;
	JScrollPane pane;
	JPanel panel;
	JFrame frame;
	Container c;
	static int val;
	int xa,ya,xb,yb,x1,y1;
	int xc,yc,xd,yd,xe,ye,xf,yf;
	int lsb=0,msb=7;
	char val1='A',val2='B';
	Thread runner=null;
	public MainDrawCycle() 
	{
		setLayout(null);
		//setSize(600,600);
		setBackground(Color.green);
		textField=new JTextField();
		label=new JLabel("Enter Clock value: ");
		button=new JButton("Ok");

		System.out.println("in const");
		label.setBounds(280,550,120,20);
		textField.setBounds(410,550,50,20);
		button.setBounds(480,550,70,20);

		add(button);
		add(textField);
		add(label);
		button.addActionListener(this);


	}

	public void paintComponent(Graphics g) 
	{

		xa=50;ya=60;xb=100;yb=60;x1=100;y1=520;
		xc=100;yc=60;xd=100;yd=100;xe=100;ye=100;xf=150;yf=100;

		Font f=new Font("serif", Font.BOLD,15);
		
		g.setColor(Color.black);
		g.drawLine(50,50,50,y1);  			// Draw Y axis.
		g.drawString("CLK",xa-40 ,ya);
		g.drawString("DATA", xa-40, 300);
		g.drawString("["+msb+":"+lsb+"]", xa-40, 312);
		
		
		g.setFont(f);
		g.setColor(Color.red);
		g.drawString("Timing Analysis", 400, 12);


		Graphics2D g2d = (Graphics2D)g;
		Stroke stroke=new BasicStroke(1f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_BEVEL,1f, new float[] {2f}, 0f);
		Stroke drawingStroke = new BasicStroke(2);

		for(int i=1;i<=val;i++)
		{
			g2d.setColor(Color.black);
			g2d.setStroke(stroke);
			Line2D line = new Line2D.Double(xb,yb,xb,500);
			g2d.draw (line);
			Line2D line2 = new Line2D.Double(xf,yf-50,xf,500);
			g2d.draw (line2); 
			g2d.setStroke(drawingStroke);

			if(x1<xf)
			{
				x1=xf;
				g.setColor(Color.black);
				g.drawLine(20,500,x1,500);  //Draw X axis.
			}
			g.drawString("t "+i,xa+30,ya-10);

			g.setColor(Color.blue);
			g.drawLine(xa,ya,xb,yb);		//h1
			g.setColor(Color.blue);         
			g.drawLine(xc,yc,xd,yd);  		//v1
			g.setColor(Color.blue);  
			g.drawLine(xe,ye,xf,yf);     	//h2
			
			if(i%2==0)
				g.drawString(""+val1,(xa+xf)/2, 300);
			else
				g.drawString(""+val2,(xa+xf)/2 , 300);

			g.drawLine(xa, 300, (xa+xb)/2, 275);
			g.drawLine((xa+xb)/2, 275, (xd+xf)/2, 275);
			g.drawLine((xd+xf)/2, 275, xf, 300);
			g.drawLine((xa+xb)/2, 325, (xd+xf)/2, 325);
			g.drawLine(xa, 300, (xa+xb)/2, 325);
			g.drawLine((xd+xf)/2, 325, xf, 300);

			xa=xf;
			ya=ya;
			xb=xe+100;
			yb=yb;

			xc=xb;
			yc=yb;
			xd=xf+50;
			yd=yf;

			xe=xd;
			ye=yd;
			xf=xe+50;
			yf=yf;



		}

	}

	public static void main(String[] args) 
	{
		JFrame frame = new JFrame();
		JScrollPane pane=new JScrollPane(new MainDrawCycle(),JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		frame.getContentPane().add(pane);
		//		new MainDrawCycle(frame);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setExtendedState(frame.MAXIMIZED_BOTH);
		
		//frame.setSize(900,700);
		frame.setVisible(true);


	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{

		if(e.getSource()==button)
		{
			val=Integer.parseInt(textField.getText());
			repaint();
			
		}

	}

	@Override
	public void run() {
		
		
		// lower ThreadPriority
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

		// run a long while (true) this means in our case "always"
		while (true)
		{

		      // repaint the applet
		      repaint();

		      try
		      {
		            // Stop thread for 20 milliseconds
		            Thread.sleep (100);
		      }
		      catch (InterruptedException ex)
		      {
		            // do nothing
		      }

		      // set ThreadPriority to maximum value
		      Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

		} 
		
		
		// TODO Auto-generated method stub
//		while(runner!=null)
//			repaint();
//		try
//		{
//			Thread.sleep(100);
//		}catch(InterruptedException i)
//		{
//			System.out.println(i.getMessage());
//		}
				
	}
public void start()
	{
		if(runner==null)
		{
			runner=new Thread(this);
			runner.start();
		}
	}	

}

One last time: What sizes did you set? - specifically for the panel where you overrode paintComponent?

JScrollPane is for dynmic contents and never works correctly by using AbsoluteLayout

Again i post my code and set panel size and frame size as mentioned in bold tag

public class MainDrawCycle extends JPanel implements ActionListener,Runnable 
{

	JButton button;
	JLabel label;
	JTextField textField;
	JScrollPane pane;
	JPanel panel;
	JFrame frame;
	Container c;
	static int val;
	int xa,ya,xb,yb,x1,y1;
	int xc,yc,xd,yd,xe,ye,xf,yf;
	int lsb=0,msb=7;
	int maxValue=20;
	char val1='A',val2='B';
	Thread runner=null;
	JComboBox cmb; 
	public MainDrawCycle() 
	{
		setLayout(null);
		//setSize(900,700);
		//setBackground(Color.green);
		textField=new JTextField();
		label=new JLabel("Enter Clock value: ");
		button=new JButton("Ok");
		cmb=new JComboBox();
		cmb.addItem("50");
		cmb.addItem("100");
		System.out.println("in const");
		label.setBounds(280,550,120,20);
		textField.setBounds(410,550,50,25);
		button.setBounds(480,550,70,25);
[B]		this.setBounds(0,0,800,600);[/B]
		cmb.setBounds(410,580,70,25);
		
		add(button);
		add(textField);
		add(label);
		add(cmb);
		button.addActionListener(this);

	}

	public void paintComponent(Graphics g) 
	{

		xa=50;ya=60;xb=100;yb=60;x1=100;y1=520;
		xc=100;yc=60;xd=100;yd=100;xe=100;ye=100;xf=150;yf=100;

		Font f=new Font("serif", Font.BOLD,15);
		
		g.setColor(Color.black);
		g.drawLine(50,50,50,y1);  			// Draw Y axis.
		g.drawString("CLK",xa-40 ,ya);
		g.drawString("DATA", xa-40, 300);
		g.drawString("["+msb+":"+lsb+"]", xa-40, 312);
		//g.drawString("Enter clock value :", 300, 560);
		
		g.setFont(f);
		g.setColor(Color.red);
		g.drawString("Timing Analysis", 500, 12);


		Graphics2D g2d = (Graphics2D)g;
		Stroke stroke=new BasicStroke(1f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_BEVEL,1f, new float[] {2f}, 0f);
		Stroke drawingStroke = new BasicStroke(2);
		maxValue++;
		for(int i=1;i<=val;i++)
		{
			
			g2d.setColor(Color.black);
			g2d.setStroke(stroke);
			Line2D line = new Line2D.Double(xb,yb,xb,500);
			g2d.draw (line);
			Line2D line2 = new Line2D.Double(xf,yf-50,xf,500);
			g2d.draw (line2); 
			g2d.setStroke(drawingStroke);

			if(x1<xf)
			{
				x1=xf;
				g.setColor(Color.black);
				g.drawLine(20,500,x1,500);  //Draw X axis.
			}
			g.drawString("t "+i,xa+30,ya-10);

			g.setColor(Color.blue);
			g.drawLine(xa,ya,xb,yb);		//h1
			g.setColor(Color.blue);         
			g.drawLine(xc,yc,xd,yd);  		//v1
			g.setColor(Color.blue);  
			g.drawLine(xe,ye,xf,yf);     	//h2
			if(i%2==0)
				g.drawString(""+val1,(xa+xf)/2, 300);
			else
				g.drawString(""+val2,(xa+xf)/2 , 300);

			g.drawLine(xa, 300, (xa+xb)/2, 275);
			g.drawLine((xa+xb)/2, 275, (xd+xf)/2, 275);
			g.drawLine((xd+xf)/2, 275, xf, 300);
			g.drawLine((xa+xb)/2, 325, (xd+xf)/2, 325);
			g.drawLine(xa, 300, (xa+xb)/2, 325);
			g.drawLine((xd+xf)/2, 325, xf, 300);
			
			xa=xf;
			ya=ya;
			xb=xe+100;   //100
			yb=yb;

			xc=xb;
			yc=yb;
			xd=xf+50;	//50
			yd=yf;

			xe=xd;
			ye=yd;
			xf=xe+50;	//50
			yf=yf;
		}

	}

	public static void main(String[] args) 
	{
		JFrame frame = new JFrame();
		JScrollPane pane=new JScrollPane(new MainDrawCycle(),JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		frame.add(pane);
		//new MainDrawCycle(frame);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//frame.setExtendedState(frame.MAXIMIZED_BOTH);
		
[B]		frame.setSize(900,700);[/B]
		frame.setVisible(true);


	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{

		if(e.getSource()==button)
		{
			val=Integer.parseInt(textField.getText());
			repaint();
			
		}
		if(e.getSource()==cmb)
		{
			if(cmb.getSelectedItem().toString()=="50")
			{
				maxValue=50;
			}
			if(cmb.getSelectedItem().toString()=="100")
			{
				maxValue=100;
			}
		}

	}

	@Override
	public void run() {
		
		
		// lower ThreadPriority
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

		// run a long while (true) this means in our case "always"
		while (true)
		{

		      // repaint the applet
		      repaint();

		      try
		      {
		            // Stop thread for 20 milliseconds
		            Thread.sleep (100);
		      }
		      catch (InterruptedException ex)
		      {
		            // do nothing
		      }

		      // set ThreadPriority to maximum value
		      Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

		} 
		
		
		// TODO Auto-generated method stub
//		while(runner!=null)
//			repaint();
//		try
//		{
//			Thread.sleep(100);
//		}catch(InterruptedException i)
//		{
//			System.out.println(i.getMessage());
//		}
				
	}
public void start()
	{
		if(runner==null)
		{
			runner=new Thread(this);
			runner.start();
		}
	}	

}

Thank you I got my problem this thred solved

That's great! Please now help everybody else here by explaining how you solved it. Thank you.

commented: hehehe +9

This is my code
first I setpreffered size of jpanel
after that setpreffred size of frame and in set jpanels prefferder size as parameter

JFrame frame = new JFrame();
		frame.setBackground(Color.darkGray);
		JPanel jp=new Test();
		jp.setPreferredSize(new Dimension(500,500));
		
		JScrollPane pane=new JScrollPane(jp,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		pane.setPreferredSize(jp.getPreferredSize());
		frame.add(pane);

Thank u!

Hai All,

i'm reading the data from the Excel and adding the data to the Container ,then 'm adding the frame to that. I'm getting the out put. I need to put Scroll . how can i add the Scrollbar/ ScrollablePane. I tried ,but i'm not able to select the value which in the bounds of the Panel . Please suggest me..

I'm posting the code please look it.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int v=ScrollPaneConstants. VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants. HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(frame,v,h);
cont = (Container) frame.getContentPane().add(jsp);
frame.setSize(800, 500);
cont.setLayout(new GridLayout(0, 1));
cont.add(new JLabel(QUES));
cont.add(OPT1);
cont.add(OPT2);
cont.add(OPT3);
cont.add(OPT4);
cont.add(OPT5);
cont=frame.getContentPane();
frame.add(jsp);

// here cont is Object of the Container and frame is JFrame.

If i'm doing this not able to select the data which is in // frame.setSize(800, 500);// bounds

Thanks for sharing code, It was so simple i was just wandaring how make jframe scrollable.. but its really simple.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.