Use the JDialog. it works the same. Just make sure this JDialog is a modal
Code:
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Test extends JFrame
{
private static final long serialVersionUID = 1L;
private final JButton button;
public Test()
{
super("Test");
button = new JButton("Click");
button.addActionListener(new ActionListener()
{
public void actionPerformed(final ActionEvent e)
{
new TestDialog(Test.this);
JOptionPane.showMessageDialog(Test.this, "Hello World!");
}
});
this.add(button);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}
public static void main(final String[] args)
{
new Test().setVisible(true);
}
}
class TestDialog extends JDialog
{
private static final long serialVersionUID = 1L;
public TestDialog(final Frame owner)
{
super(owner, true);
this.add(new JTextField("Hello World!"));
setLocationRelativeTo(owner);
pack();
setVisible(true);
}
}