如何设置时,框架被拖动文本字段下方的JWindow的位置? [英] How to set the location of a JWindow below the textfield when the frame is being drag?
问题描述
我想提出一个自动完成的项目(就像谷歌)。我有一个JTextField在我的框架,每当我输入一些东西到该领域,一个的JWindow将出现在文本框的下方,该窗口从另一个类的到来。
I am making an autocomplete project(just like Google). I have a jtextfield in my frame and whenever I type something to that field, a JWindow will appear below the textfield and that window is coming from another class.
现在的问题是,我怎么可能让窗口总是出现在文本框下方,每当我拖动框架?
Now the problem is how could I make the window always appear below the textfield whenever I drag the frame?
任何帮助将是非常美联社preciated ..谢谢...
Any help would be much appreciated.. Thanks...
推荐答案
手动设置 Locatio
N,你必须定义什么是私人点的位置;
和的getLocation
从所需的JComponent
,不要忘记dealyed秀为显示顶层容器到的invokeLater();
for manually set Locatio
n on the screen, you have to define something as private Point location;
and getLocation
from desired JComponent
, don't forget dealyed show for Show Top-Level Container into invokeLater();
例如:
public void showWindow() {
window.setVisible(false);
location = myTextField.getLocationOnScreen();
int x = location.x;
int y = location.y;
window.setLocation(x - 20, y - 20);
Runnable doRun = new Runnable() {
@Override
public void run() {
window.setVisible(true);
}
};
SwingUtilities.invokeLater(doRun);
}
这篇关于如何设置时,框架被拖动文本字段下方的JWindow的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!