如何在Java中定位输入对话框?

时间:2015-08-13 19:42:28

标签: java dialog jframe

以下代码创建一个输入对话框。我该如何定位?我尝试了begin.setLocation(X,Y),但这没有用。我不知道为什么。

JFrame begin = new JFrame();
Object subjectnumber = JOptionPane.showInputDialog(begin, "Please enter subject number:");

1 个答案:

答案 0 :(得分:1)

调用.setLocation()无效,因为您已将其指定为基本Object类型。

尝试将您的定义调整为

JOptionPane subjectnumer = new JOptionPane();
subjectnumber.setLocation(x, y);
String result = subjectnumber.show.....

基本Object没有方法setLocation,但JOptionPane没有。