You are already using JDialog.
That's fine!
There are a lot of dialog configurations possible, so please take a look here:
How to Make Dialogs @ Oracle Tutorial[
^]
But sometimes you want some more to be in such a dialog.
How about giving JDialog some more love:
public class MyDialog extends JDialog{
private final Component parent;
public MyDialog(final Component parent){
this.parent = parent;
this.init();
}
private void init(){
this.setLocationRelativeTo(parent);
}
}
you can then call that by using:
static void displayJFrame()
{
JButton showDialogButton= new JButton ("Show dialog box");
showDialogButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
MyDialog d = new MyDialog(frame);
d.setVisible(true);
}
});
}
Also please think about whether you need a dialog (modal) or more a second frame (non modal) or if you even want to create a
Wizard[
^] with multiple steps in dialogs.
EDIT:
Your code needs some improvement.
You need to break out of that static context.
That will make your coding much simpler.
compare this to your coding:
public class test_dialogue_1
{
public static void main(String[] args)
{
test_dialogue_1 dialog = new test_dialogue_1();
dialog.displayJFrame();
}
private void displayJFrame(){
}
You see, that is not even the static member variable any more. It's not used outside the main function, so there is no need to make a member.