Hi...

i want to align the components on the panel so that the components r fixed on the panel ..and the page should be scroll down so that i want to add scrollPane to it..can anyone help me....

This is my Code.............

//contact Details
import javax.swing.*;

import java.awt.*;

public class FirstScreen extends JFrame
{
  private JLabel jl,jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8;

  private JTextField jtf,jtf1,jtf2,jtf3,jtf4,jtf5; 

  private JTextArea jta1;

  private JScrollPane jsp;

  private JPanel jp;

  public FirstScreen()
    {
      super("Details");
      create();
       this.setVisible(true);
    }

  private void create()
  {
    jl=new JLabel("Date :");

    jl.setFont(new Font("Arial",Font.BOLD,15));

    jl1=new JLabel("<HTML><H3><U>ENQUIRER DETAILS</U></H3></html>");

     jl1.setFont(new Font("Arial",Font.BOLD,20));

     jl2=new JLabel("Name:");

     jl2.setFont(new Font("Arial",Font.BOLD,17));

    jl3=new JLabel("Address:");

    jl3.setFont(new Font("Arial",Font.BOLD,15));

    jl4= new JLabel("Email Address:");

    jl4.setFont(new Font("Arial",Font.BOLD,15));

    jl5= new JLabel("Contact Number:");

    jl5.setFont(new Font("Arial",Font.BOLD,15));

    jl6= new JLabel("Residence:");

    jl6.setFont(new Font("Arial",Font.BOLD,15));

    jl7= new JLabel("Office:");

    jl7.setFont(new Font("Arial",Font.BOLD,15));

    jl8= new JLabel("Mobile:");

    jl8.setFont(new Font("Arial",Font.BOLD,15));

    jtf=new JTextField();

    jtf1=new JTextField();

    jtf2=new JTextField();

    jtf3=new JTextField();

    jtf4=new JTextField();

    jtf5=new JTextField();

    jta1=new JTextArea();

    jsp=new JScrollPane(jta1);

    jp = (JPanel)this.getContentPane();

    jp.setLayout(null);

    addComponent(jp,jl,500,10,100,20);

    addComponent(jp,jl1,250,40,200,20);

    addComponent(jp,jl2,100,80,200,40);

    addComponent(jp,jl3,100,130,200,40);

    addComponent(jp,jl4,100,180,200,40);

    addComponent(jp,jl5,100,230,200,40);

    addComponent(jp,jl6,200,260,200,40);

    addComponent(jp,jl7,200,300,200,40);

    addComponent(jp,jl8,200,340,200,40);






    addComponent(jp,jtf,550,10,100,20);

    addComponent(jp,jtf1,250,80,300,30);

    addComponent(jp,jsp,250,120,300,50);

    addComponent(jp,jtf2,250,180,300,30);

    addComponent(jp,jtf3,300,260,250,30);

    addComponent(jp,jtf4,300,300,250,30);

    addComponent(jp,jtf5,300,340,250,30);




    this.setSize(800,600);

    this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    this.setResizable(true);
       }

    // Add Component Without a Layout Manager (Absolute Positioning) 

  private void addComponent(Container container,Component c,int x,int y,int width,int height)
       {
     c.setBounds(x,y,width,height);
     container.add(c);
      }

  public static void main(String args\])
      {
        FirstScreen f= new FirstScreen();
        f.setVisible(true);
      }
}

>i want to align the components on the panel so that the components r fixed on the panel ..and the page should be scroll down so that i want to add scrollPane to it..can anyone help me....

Well your components are already in fixed position.
to get scroll bars on JScrollPane you just need to setup setHorizontalScrollBarPolicy and setVerticalScrollBarPolicy something as following

jsp=new JScrollPane(jta1, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

Also you may want to set your JFrame as setResizable(false)

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.