简体   繁体   English

Java Swing; 单击按钮时是否有办法,将在该按钮旁边显示一个弹出窗口

[英]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: 我有一个JButton,它具有如下回调函数:

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

The myFrame pops up on the upper left hand corner of the screen. myFrame弹出在屏幕的左上角。 My question: is there a property that controls where the pop up pops up? 我的问题:是否有一个属性控制弹出窗口的弹出位置?

Thanks 谢谢

Window.setLocationRelativeTo(Component)

If myFrame extends component there is the [setLocation(int x, int y)][1] method. 如果myFrame扩展了组件,则有[setLocation(int x,int y)] [1]方法。

There is also the setLocationRelativeTo( Component c ) method. 还有setLocationRelativeTo(Component c)方法。

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

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 您可以使用getLocationOnScreen方法获取按钮的位置,然后使用[setLocation] [2]设置JFrame的位置

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM