| | |
adding scrollPane to panel with components aligned at fixed bounds
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
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....
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
Also you may want to set your JFrame as setResizable(false)
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
Java Syntax (Toggle Plain Text)
jsp=new JScrollPane(jta1, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- Problem changing contents of JTable when button is pressed... (Java)
- Display image for background (Java)
- Please help with Aurora (Viruses, Spyware and other Nasties)
- Search Method help needed!!! (Java)
- Bought a new CPU for my comp. (Motherboards, CPUs and RAM)
- Adding fans? (Cases, Fans and Power Supplies)
- Working with JLayeredPane and positioning of components.. HELP! (Java)
Other Threads in the Java Forum
- Previous Thread: doubt in applets
- Next Thread: How to develop Comparison Shopping ?
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor






