开发者

Java Swing; is there a way when clicking a button, a popup will appear NEXT TO THAT BUTTON

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


Window.setLocationRelativeTo(Component)


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)


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜