I am not able to use scroll bars with absolute layout in Swing.
I don't wish to use this layout but I have to display dynamic objects on my panel on click of a button and align them using setBounds which can be done using this layout only (I guess).
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class clothes2 extends javax.swing.JFrame {
    JTextField n=null;
    JButton m=null;
    public clothes2(){
        initComponents();
    }
    public void initComponents() {
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());
        final JPanel jp = new JPanel();
        contentPane.setPreferredSize(new Dimension(320,200));
        jp.setLayout(null);
        m=new JButton("add");
        m.setBounds(0,0,50,50);
        jp.add(m);
        m.addMouseListener( new MouseAdapter() {
            int x=0;
            int y=0;
            public void mouseClicked(MouseEvent me){
                x+=100;
                y+=100;
                jp.add(n=new JTextField("Name"));
                n.setBounds(x, y, 50, 50);
                jp.add(n=new JTextField("code"));
                x+=100;
                n.setBounds(x,y, 50, 50);
                jp.revalidate();
                jp.repaint();
                x=0;
            }
        });
        int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
        int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
        JScrollPane jsp = new JScrollPane(jp, v, h);
        contentPane.add(jsp, BorderLayout.CENTER);
    }
    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame f= new clothes2();
                f.setVisible(true);
                f.setSize(640,320);
            }
        });
    }
}
 
     
     
     
     
    
 
    