validate() problem
i add some labels on form and i can drag and drop those labels. it works but when i add a new label all other labels go back their first position. i think it is because of validate() method. but how can i refresh form. here is my code...
import java.awt.event.*;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
publicclass ekleextends JFrameimplements MouseMotionListener,MouseListener{
Point location;
MouseEvent pressed;
ArrayList v;
Container c;
int i=0;
public ekle(){
JButton but;
c=getContentPane();
c.setLayout(new FlowLayout());
v=new ArrayList(10);
but=new JButton("Click");
c.add(but);
but.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent event){
JLabel T=new JLabel("deneme label");
addcomp(T);
}});}
publicvoid addcomp(Component Co){
Co.addMouseMotionListener(this);
Co.addMouseListener(this);
v.add(i,Co);
c.add(Co);
c.validate();
i++;
}
publicvoid mousePressed(MouseEvent e)
{
pressed = e;
}
publicvoid mouseClicked(MouseEvent e){}
publicvoid mouseReleased(MouseEvent e){}
publicvoid mouseDragged(MouseEvent e)
{
int j=0;
while(j<v.size()){
Component comp= (Component)v.get(j);
if(e.getSource()==comp){
location = comp.getLocation(location);
int x = location.x - pressed.getX() + e.getX();
int y = location.y - pressed.getY() + e.getY();
comp.setLocation(x,y);
}
j++;
}
}
publicvoid mouseMoved(MouseEvent e){}
publicvoid mouseEntered(MouseEvent e){}
publicvoid mouseExited(MouseEvent e){}
publicstaticvoid main(String args[]){
ekle pen =new ekle();
pen.setSize(500,300);
pen.setVisible(true);
}
}
>

