adding scrollPane to panel with components aligned at fixed bounds

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2007
Posts: 5
Reputation: vinutha1309 is an unknown quantity at this point 
Solved Threads: 0
vinutha1309 vinutha1309 is offline Offline
Newbie Poster

adding scrollPane to panel with components aligned at fixed bounds

 
0
  #1
Jul 21st, 2007
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);
}
}


Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,213
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: adding scrollPane to panel with components aligned at fixed bounds

 
0
  #2
Jul 21st, 2007
>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
  1. jsp=new JScrollPane(jta1, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
Also you may want to set your JFrame as setResizable(false)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC