How can I position Panels at specified locations in a frame. I know about BorderLayout, this layout is not suitable for my needs. I want to be able to, if possible, position panels at specified X Y coordinates.
Printable View
How can I position Panels at specified locations in a frame. I know about BorderLayout, this layout is not suitable for my needs. I want to be able to, if possible, position panels at specified X Y coordinates.
You can use setLocation(x,y) or setLocation(Point p) :)
thanks....for reply
but I have already used that method and required objective is completed.
I'm again in trouble.
problem is I'm added a panel in applet and panel is moving in all direction on mouse move.
I'm added mouselistener in applet and check as:
code: in init() method of JApplet.
JPanel mp=new JPanel();
getContentPane().setLayout(null);
getContentPane().add(mp);
mp.setLocation(-100000,-100000);
mp.setSize(50000000,50000000);
addMouseMotionListener(new MouseMotionAdapter(){
public void mouseMoved(MouseEvent me){
if(me.getX()>1000){
mp.setLocation(mp.getX()-200,mp.getY());
mp.setSize(mp.getWidth()+200,mp.getHeight());
}
else if(me.getX()<100){
mp.setLocation(mp.getX()+200,mp.getY());
mp.setSize(mp.getWidth()-200,mp.getHeight());
}
else if(me.getY()<100){
//if(mp.getY()<vs.getY()){
mp.setLocation(mp.getX(),mp.getY()+200);
mp.setSize(mp.getWidth(),mp.getHeight()-200);
//}
}
else if(me.getY()>650){
mp.setLocation(mp.getX(),mp.getY()-200);
mp.setSize(mp.getWidth(),mp.getHeight()+200);
}
}
}
);
but I want add mouselistener in panel.
[mp.addMouseMotionListener();]
problem is I can't define if condition as above.
please help me....
again thanks for study my problem.
So you are basicaly having trouble nesting your if's? As it stands now it looks like you have a mouse listener for your applet not the panel.