gpt4 book ai didi

java - 将 JDialog 定位为出现在 Swing 中的 JTextField 下方?

转载 作者:搜寻专家 更新时间:2023-11-01 03:29:39 27 4
gpt4 key购买 nike


我想将 JDialog 框放在 JFrame 的 JTextField 下方,当对话框打开时,我的 JFrame 不能移动——也就是说,它不能拖动。有什么建议吗?

最佳答案

public class DialogTest {
public static void main(String[] args) {

final JFrame frame = new JFrame("Frame");
JTextField field = new JTextField("Click me to open dialog!");
field.addMouseListener(new MouseAdapter() {

@Override
public void mousePressed(MouseEvent e) {
JTextField f = (JTextField) e.getSource();
Point l = f.getLocationOnScreen();

JDialog d = new JDialog(frame, "Dialog", true);
d.setLocation(l.x, l.y + f.getHeight());
d.setSize(200, 200);
d.setVisible(true);
}
});
frame.add(field);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 100);
frame.setVisible(true);
}
}

关于java - 将 JDialog 定位为出现在 Swing 中的 JTextField 下方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4025373/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com