I think messed everything up. I have tried creating popup windows when MouseEntered
event fires. How can I fix this?
Popup p=factory.getPopup(c,null,x,y);
I am not sure about parameters
Rest of this code:
public class pop extends JFrame{
class mypopUpShow implements ActionListener{
JComponent c;
// final Random random;
public mypopUpShow(JComponent c){
this.c=c;
}
@Override
public void actionPerformed(ActionEvent ae) {
Random random=new Random();
int x = random.nextInt(200);
int y = random.nextInt(200);
PopupFactory factory=PopupFactory.getSharedInstance();
Popup p=factory.getPopup(c,null,x,y);
p.show();
}
}
public pop() {
JPanel Panel=new JPanel();
final Timer t=new Timer(100, new mypopUpShow(Panel));
MouseListener listener=new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent me){
t.start();
}
};
setSize(300,300);
Panel.addMouseListener(listener);
add(Panel);
}
public static void main(String...arg){
new pop().setVisible(true);
}
}
The problem is that you are setting the 'contents' parameter for getPopup(Component owner, Component contents, int x,int y) to null. This is why you are getting an IllegalArgumentException. Try changing null to something like "new JButton("TEST")" and you will see a ton of buttons popup. The contents is what you want to popup (a widget, a panel, a window, etc).