Absolute Positioning for two JPanel (Urgent)

How do i add work with two Jpanel with Absoulte position?

publicclass MedicineUIextends JPanel{

private JPanel c;

JTextField patient_name;

/** Creates a new instance of MedicineUI */

public MedicineUI(){

patient_name=new JTextField();

patient_name.setBounds(new Rectangle(0, 0, 20, 30));

add(patient_name);

JLabel name=new JLabel("test");

name.setBounds(new Rectangle(40, 40, 20, 30));

add(name);

}

}

package sucure;

import java.io.*;

import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

import java.awt.event.*;

publicclass AddConsultationextends JFrameimplements ActionListener

{

JLabel lb_date,lb_name,lb_nric,lb_illness,lb_prescription;

JTextField tb_name,tb_nric,tb_illness,tb_date;

JButton btn_submit,btn_reset;

JPanel p1;

int x,y;

public AddConsultation(){

Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

x = (screen.width);

y = (screen.height);

this.setDefaultLookAndFeelDecorated(true);

this.setTitle("SuCure System");

this.setBounds(x/4,y/4,0,0);

this.setSize(new Dimension(600, 400));

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

p1 =new JPanel();

p1.setBounds(new Rectangle(0, 0, x, 30));

lb_name =new JLabel("Name:",Label.LEFT);

lb_name.setBounds(new Rectangle(0, 50,100, 30));

lb_nric =new JLabel("Nric:",Label.LEFT);

lb_nric.setBounds(new Rectangle(0, 80,100, 30));

lb_date =new JLabel("Date:",Label.LEFT);

lb_date.setBounds(250,50,100,30);

tb_name =new JTextField("");

tb_name.setBounds(80,55,150,25);

tb_nric =new JTextField("");

tb_nric.setBounds(80,85,150,25);

JButton btn_add=new JButton("test");

btn_add.setMnemonic(KeyEvent.VK_A);

btn_add.setBounds(new Rectangle(180, 200, 90, 40));

btn_add.setActionCommand("test");

btn_add.addActionListener(this );

p1.setLayout(null);

p1.add(btn_add);

p1.add(lb_name);

p1.add(lb_nric);

p1.add(lb_date);

p1.add(tb_name);

p1.add(tb_nric);

getContentPane().add(p1);

}

publicvoid actionPerformed(ActionEvent e)

{

if (e.getActionCommand().equals("test"))

{

MedicineUI p2=new MedicineUI();

p2.setBounds(new Rectangle(0, 30, x, y-30));

getContentPane().add(p2);

}

}

publicstaticvoid main(String[] args){

AddConsultation c =new AddConsultation();

c.setVisible(true);

}

}

Message was edited by:

gohgss

[4854 byte] By [gohgssa] at [2007-10-3 8:28:11]
# 1
All Containers have a layout manager by default which move and resize the components. If you want absolute position then set the layout manager to null.JPanel p = new JPanel();p.setlayout(null);
mpmarronea at 2007-7-15 3:34:53 > top of Java-index,Desktop,Core GUI APIs...
# 2

You just had a posting with 20 responses on this topic. So read the tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html]Laying Out Components in a Container[/url]. Four times in that posting you where given a link to that tutorial. So know its time to actually read it an look at the examples.

Virtually everybody in this forum advises against using "Absolute Positioning" because using Layout Managers provide so many benefits.

But if you insist on using a null layout then read the tutorial and understand the example and then go from there, but don't expect us to debug your program for you. This is in no way urgent.

As you where told earlier you can't just add two components to the same space in a container. I even gave you two suggests on solving this problem. Since your code incorporates neither of these suggestion, you are on your own.

camickra at 2007-7-15 3:34:53 > top of Java-index,Desktop,Core GUI APIs...