简体   繁体   English

关闭JDialog后运行语句

[英]Running a statement after closing JDialog

I created my main JFrame and added a button with click event that will show my JDialog named AddProductGUI. 我创建了我的主JFrame,并添加了一个带有click事件的按钮,该按钮将显示名为AddProductGUI的JDialog。

AddProductGUI addProductGUI = new AddProductGUI();
addProductGUI.AddNewProduct();
JOptionPane.showMessageDialog(contentPane, "message");

My code for AddNewProduct(), my constructor just position each component. 我的AddNewProduct()代码,我的构造函数只是定位每个组件。

public void AddNewProduct() {
        addProductGUI = new AddProductGUI();
        addProductGUI.setAlwaysOnTop(true);
        addProductGUI.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        addProductGUI.txtProductID.setText("");
        addProductGUI.txtCode.setText("");
        addProductGUI.txtName.setText("");
        addProductGUI.txtBrand.setText("");
        addProductGUI.setVisible(true);
}

AddNewProduct() method simply just shows the JDialog and sets the textfields without text. AddNewProduct()方法只是显示JDialog并设置没有文本的文本字段。 My problem is when my AddProductGUI appears the my message dialog also appear. 我的问题是当我的AddProductGUI出现时,我的消息对话框也会出现。 How can I make my message dialog appear only after closing JDialog? 如何在关闭JDialog后才能显示我的消息对话框?

I guess your AddProductGUI extends JDialog . 我想你的AddProductGUI扩展了JDialog Then take a look to constructor from JDialog you have to set modal true . 然后从JDialog看一下构造函数,你必须设置modal true JDialog api . JDialog api By the way in java by convention method's name starts with lower-case. 顺便说一句,在java中,方法的名称以小写字母开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM