我必须在JDialog中显示一个Jpanel,到目前为止我处理了它,但是我不知道如何在处理它之前关闭对话框并在Jpanel中接收数据。
newButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent event)
{
JDialog dialog = new JDialog(Main.getMainFrame(), true);
JPanel jPanel = new JPanel();
dialog.getContentPane().add(jPanel);
dialog.setMinimumSize(new Dimension(600, 800));
dialog.setVisible(true);
if (jPanel.close)
{
/*read some useful information from the jpanel*/
dialog.setVisible(false);
dialog.dispose();
}
}
});
到目前为止,我已经在 Jpanel 中放置了一个按钮,该按钮设置了一个布尔关闭 = true,对话框会读取它并自行处理。但是这不起作用:我怀疑在我单击JPanel内部关闭之前测试了jPanel.close()
,而它应该等待实际收盘值发生变化。
您可以使用
这样的代码来获取容器窗口实例(在我们的例子中JDialog
)
JDialog parentDialog=(JDialog)SwingUtilities.getWindowAncestor(jPanel);