tags:

views:

46

answers:

3

Hi.

I have a JButton that has a callback function like so:

myJButtonCallBackFunc (ActEvtListener evt) {
    myFrame.pack();
    myFrame.setVisible(true);
}

The myFrame pops up on the upper left hand corner of the screen. My question: is there a property that controls where the pop up pops up?

Thanks

A: 

If myFrame extends component there is the [setLocation(int x, int y)][1] method.

There is also the setLocationRelativeTo( Component c ) method.

[1]: http://download-llnw.oracle.com/javase/6/docs/api/java/awt/Component.html#setLocation(int, int)

HeathLilley
+3  A: 

Window.setLocationRelativeTo(Component)

Steve Emmerson
perfect! exactly what I was looking for
Carlo del Mundo
A: 

You can get the location of the button using the getLocationOnScreen method and then use the [setLocation][2] to set the position of the JFrame

[2]: http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Component.html#setLocation(int, int)

npinti