我想将 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/