Question

I created my main JFrame and added a button with click event that will show my JDialog named AddProductGUI.

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

My code for AddNewProduct(), my constructor just position each component.

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. My problem is when my AddProductGUI appears the my message dialog also appear. How can I make my message dialog appear only after closing JDialog?

Was it helpful?

Solution

I guess your AddProductGUI extends JDialog . Then take a look to constructor from JDialog you have to set modal true. JDialog api. By the way in java by convention method's name starts with lower-case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top